Chapter 5: Parallel dVegas

5.1: Shared memory multiprocessor machines (SMP)

If a Posix threads implementation exists for your platform you can link your programs with the parallel dVegas libraries libdvegas_r.a, libf_dvegas_r.a, libc_dvegas_r.a (for C++, Fortran and C, respectively) to take full advantage of multiprocessor machines. "_r" stands for reentrant. Note that these libraries are not reentrant themselves, rather the "_r" suffix is introduced to remind you that when using the parallel libraries the integrand function/subroutine has to be reentrant, aka thread-safe and MT-safe. Reentrant essentially means that several copies of a function can be executed simultaneously without interfering with each other. If this is not the case the program will crash or yield arbitrary results.

C++ and C functions that do not write to global variables or use local variables declared "static" are typically reentrant. Fortran subroutines can present more problems. Some advice:

Variables that appear in a SAVE statement or are initialized in a DATA statement are always allocated statically and will corrupt the threaded version. Make sure no values are assigned to COMMON block variables in the subroutines called by fxn.

If you call Fortran subroutines in fxn make sure that all local variables are put on the run-time stack by using the corresponding compiler option, typically -automatic. The default behavior is very likely static allocation. (The GNU Fortran compiler is an exception to the rule, with automatic allocation being the default. It has an option -fno-automatic.)

Note: Static variables (default, -static) are always initialized to default (or DATA statement) values before the subroutine is executed. Variables put on the run-time stack (-automatic) are NOT initialized automatically before the subroutine is executed and thus don't have a well-defined value until they get a value assigned when an assignment statement is executed. Using uninitialized variables in expressions (e.g. on the right side of an assignment statement) triggers floating exception signals in threads.

The following sections contain platform specific notes about writing code and creating excetables with the parallel dVegas libraries. Please report any problems (and solutions) you find when using these libraries, so that we can address them. See section 1.6 for details.

For documented platforms you might want to run make test and look at the test programs for the parallel libraries and check out how they are compiled.

5.1.1: Intel/Linux

No special issues known. Just link with -lpthread.

5.1.2: Alpha/Tru64 Unix

Use -pthread option for all Compaq compilers when compiling or linking. Use -automatic when compiling or linking with the Compaq Fortran compiler.

5.2: Workstation clusters

A dVegas library for distributed computing is not yet available. However, adapting the SMP code for workstation clusters is straightforward. The standard choice in scientific computing would be the Message Passing Interface (MPI). However, I believe that a CORBA-based solution would be easier to install and use, as well as more flexible and transparent. In spring 2002, I plan to integrate dVegas into a truly component-oriented, multi-process, CORBA-based architecture for Monte Carlo computations using the free, high-performance implementation from AT&T Laboratories Cambridge (omniORB). See omnicomp at hepsource.org for a preview. If you are familiar with MPI and would like to contribute code for MPI, please contact me.