Skip to content

HOWTO: Modifying a McStas 2 instrument for use under McStas 3

Peter Willendrup edited this page Nov 29, 2022 · 7 revisions

1) Local components

If there are any “local” or home-grown components used in the instrument, these also need adaptation. See HOWTO: Modifying a McStas 2 component for use under McStas 3

2) Examples

For examples of converted instruments please compare the mcstas 3.1 example suite with that of mcstas 2.7.1

3) Essential modifications of your instrument

  • Any “flag” oriented DECLARE variable, i.e. things declared in
DECLARE %{
  int flag;
%}

and later used in e.g.

EXTEND %{
  flag = SCATTERED;
%}

must be moved from DECLARE to become a USERVAR, i.e. moved from DECLARE to USERVARS:

USERVARS %{
  int flag;
%}
  • DECLARE-based functions used in TRACE / EXTEND / WHEN will need a #pragma acc routine - if they are to be GPU-compatible. Any such function that uses e.g. rand01() inside must have a footprint that includes _class_particle* _particle for forwarding RNG information

  • If instrument input-parameters are used in EXTEND blocks these must be called using INSTRUMENT_GETPAR(variablename) (Often these will be present as mcipvariablename in McStas 2)

  • If Monitor_nD instances are present that use user1, user2, user3, the names should be defined as strings in the COMPONENT instance, i.e.

COMPONENT A = Monitor_nD(…., user1=flag) should become COMPONENT A = Monitor_nD(…., user1=“flag")

  • If non-flag DECLARE variables are to be used in WHEN or EXTEND on a GPU, these need to become global variables like this
DECLARE %{
  double myvar;
  #pragma acc declare create(myvar)
%}
INITIALIZE %{
  myvar=5;
  #pragma acc update device(myvar)
%}

4) What to do if problems persists

If compilation still fails, feel free to write us an issue (https://github.com/McStasMcXtrace/McCode/issues) or send mcstas-users@mcstas.org an email including instruments and comps :)

Clone this wiki locally