|
|
|
|||
|
About McXtrace Documentation |
5.2 Running the instrument compilerThis section describes how to run the McXtrace compiler mcxtrace manually. Often, it will be
more convenient to use the front-end program Upon a command of the form 1 mcxtrace name.instr 2 the compiler mcxtrace will read the instrument definition 1 mcxtrace -o code.c name.instr 2 which gives the output in the file 5.2.1 Code generation optionsBy default, the code generated by mcxtrace is ISO-C with some extensions (currently the only
extension is the creation of new directories, which is not possible in pure ISO-C). The
use of extensions may be disabled with the By default ( The code generation options can also be controlled by using preprocessor macros in the C
compiler, without the need to re-run mcxtrace. If the preprocessor macro 1 cc -DMC_TRACE_ENABLED -DMC_PORTABLE ... 2 Finally, the Alternative code generator: mccode-antlrFrom McXtrace 3.5 onwards an alternative code generator, mcxtrace-antlr, is available alongside the classic generator. It is built on the ANTLR parser framework rather than the traditional lex/yacc toolchain, is implemented primarily in Python, and is a candidate replacement for the default generator in future releases. Select it on a per-run basis with the --cogen flag: mxrun --cogen=mcxtrace-antlr MyInstrument.instr -n 1e8
The active code generator can also be set permanently by editing the MCCOGEN field in mccode_config.json. This file is accessible from the command line with: mxrun --edit-user-config or via the Save/Edit configuration dialogue inside mxgui. At the time of the McXtrace 3.6 release, mcxtrace-antlr is close to feature-complete for CPU simulations with a few more issues for GPU/OpenACC simulations. Alternative code generator: mcxtrace-pygenA third code generator, mcxtrace-pygen, targets McStasScript [Mcs] (a Python package for
building and running instruments, including McXtrace ones) rather than C: given an .instr
file, it generates an equivalent McStasScript Python module instead of a C program. Besides
1import mcstasscript as ms 2from INSTRUMENT_generated import make 3instr = make() 4instr.show_diagram() 5instr.show_instrument() 6data = instr.backengine() 7ms.make_sub_plot(data) The generator is normally invoked indirectly, via mcxtrace-jupylab (section 5.4.3), rather than run directly by the user. 5.2.2 Specifying the location of filesThe McXtrace compiler mcxtrace needs to be able to find various files during compilation,
some explicitly requested by the user (such as component definitions and files referenced by
The location of the special McXtrace directory is set when mcxtrace is compiled. It defaults
to /usr/share/mcxtrace/version on Debian and derivatives, to /usr/local/mcxtrace/version on
RedHat and derivatives and on other Unix-like systems, including Mac OS X, where it is a link to
the actual location /Applications/McXtrace-version.app/Contents/Resources/mcxtrace/version,
and C: The location can be overridden by setting the environment variable 1 setenv MCXTRACE /home/joe/mcxtrace 2 for csh/tcsh users, or 1 export MCXTRACE=/home/joe/mcxtrace 2 for bash/Bourne shell users. Windows users should define To make mcxtrace search additional directories for component definitions and include files,
use the 1 mcxtrace -I/home/joe/components -I/home/joe/mcxtrace/include name.instr Multiple 5.2.3 Embedding the generated simulations in other programsBy default, mcxtrace will generate a stand-alone C program, which is what is needed in most cases. However, for advanced usage, such as embedding the generated simulation in another program or even including two or more simulations in the same program, a stand-alone program is not appropriate. For such usage, mcxtrace provides the following options:
Users that need these options are encouraged to contact the authors for further help. 5.2.4 Running the C compilerAfter the source code for the simulation program has been generated with mcxtrace, it must be compiled with the C compiler to produce an executable. Since the generated C code obeys the ISO-C standard, it should be easy to compile it using any ISO-C (or C++) compiler. E.g. a typical Unix-style command would be 1 cc -O -o name.out name.c -lm The McXtrace team recommends these compiler alternatives for the Intel (and AMD) hardware architectures:
The Monte Carlo simulations are computationally intensive, and it is often desirable to have them run as fast as possible. Some success can be obtained by adjusting the compiler optimization options. Here are some example platform and compiler combinations that have been found to perform well (up-to-date information will be available on the McXtrace WWW home page [Mcx]):
Optimization flags will typically result in a speed improvement by a factor about 3, but the compilation of the instrument may be 5 times slower. A warning is in place here: it is tempting to spend far more time fiddling with compiler
options and benchmarking than is actually saved in computation times. Even worse, compiler
optimizations are notoriously buggy; the options given above for PGCC on Linux
and the ISO-C compiler for HPUX have been known to generate incorrect code
in some compiler versions. mcxtrace actually puts an effort into making the task
of the C compiler easier, by in-lining code and using variables in an efficient way.
As a result, McXtrace simulations generally run quite fast, often fast enough that
further optimizations are not worthwhile. Also, optimizations are highly time and
memory consuming during compilation, and thus may fail when dealing with large
instrument descriptions (e.g. more that 100 elements). The compilation process
is simplified when using components of the library making use of shared libraries
(see |
||||
| |||||