- Home
- User Articles
- How to Write User-Defined Sources and Scatter Functions in Fortran
- Home
- Programming ZEMAX
- Extensions
- How to Write User-Defined Sources and Scatter Functions in Fortran
- Home
- Non Sequential Ray Tracing
- Sources, Splitting and Scattering
- How to Write User-Defined Sources and Scatter Functions in Fortran
How to Write User-Defined Sources and Scatter Functions in Fortran
- By Jeff Casey
- Published 10 December 2007
- User Articles , Extensions , Sources, Splitting and Scattering
-
Rating:




Multi-Threaded Code
ZEMAX takes full advantage of multiple CPUs if they are available. The extension software must be written to be compatible with multiple threads. For example, some of my early attempts used the compiler-supplied function for random number generation. This works fine if ZEMAX is forced to only use a single CPU, but generates erratic failures if multiple CPUs are used in a multi-core machine. (These are not frequent failures, but will occur at low probability, depending on the likelihood of collision by multiple processes – as an example, this glitch usually only occurred if > 106 rays were traced on a dual-core system).
The Lahey/Fujitsu compiler does not provide switches for multi-threaded compatibility, but it does provide such switches for generating re-entrant code. Since parameters are kept on the stack with re-entrant calls, this similarly solves the compatibility problem. Your code, therefore, should be completely self-contained, and internal routines should be specified with the RECURSIVE flag.
The Lahey/Fujitsu compiler does not provide switches for multi-threaded compatibility, but it does provide such switches for generating re-entrant code. Since parameters are kept on the stack with re-entrant calls, this similarly solves the compatibility problem. Your code, therefore, should be completely self-contained, and internal routines should be specified with the RECURSIVE flag.