There is the experimental inclusion of FLASH multithreading with OpenMP in the FLASH4 beta release. The units which have support for multithreading are split hydrodynamics 15.1.2, unsplit hydrodynamics 15.1.3, Gamma law and multigamma EOS 17.2, Helmholtz EOS 17.3, Multipole Poisson solver (improved version (support for 2D cylindrical and 3D cartesian)) 8.10.2.2 and energy deposition 18.4.
The FLASH multithreading requires a MPI-2 installation built with thread support (building with an MPI-1 installation or an MPI-2 installation without thread support is possible but strongly discouraged). The FLASH application requests the thread support level MPI_THREAD_SERIALIZED to ensure that the MPI library is thread-safe and that any OpenMP thread can call MPI functions safely. You should also make sure that your compiler provides a version of OpenMP which is compliant with at least the OpenMP 2.5 (200505) standard (older versions may also work but I have not checked).
In order to make use of the multithreaded code you must setup your application with one of the setup variables threadBlockList, threadWithinBlock or threadRayTrace equal to True, e.g.
./setup Sedov -auto threadBlockList=True ./setup Sedov -auto threadBlockList=True +mpi1 (compatible with MPI-1 - unsafe!)
When you do this the setup script will insert USEOPENMP = 1 instead of USEOPENMP = 0 in the generated Makefile. If it is equal to the Makefile will prepend an OpenMP variable to the FFLAGS, CFLAGS, LFLAGS variables.
The OpenMP variables should be defined in your Makefile.h and contain a compiler flag to recognize OpenMP directives. In most cases it is sufficient to define a single variable named OPENMP, but you may encounter special situations when you need to define OPENMP_FORTRAN, OPENMP_C and OPENMP_LINK. If you want to build FLASH with the GNU Fortran compiler gfortran and the GNU C compiler gcc then your Makefile.h should contain
OPENMP = -fopenmp
If you want to do something more complicated like build FLASH with the Lahey Fortran compiler lf90 and the GNU C compiler gcc then your Makefile.h should contain
OPENMP_FORTRAN = -openmp -Kpureomp OPENMP_C = -fopenmp OPENMP_LINK = -openmp -Kpureomp
When you run the hybrid FLASH application it will print the level of thread support provided by the MPI library and the number of OpenMP threads in each parallel region
[Driver_initParallel]: Called MPI_Init_thread - requested level 2, given level 2 [Driver_initParallel]: Number of OpenMP threads in each parallel region 4
Note that the FLASH application will still run if the MPI library does not provide the requested level of thread support, but will print a warning message alerting you to an unsafe level of MPI thread support. There is no guarantee that the program will work! I strongly recommend that you stop using this FLASH application - you should build a MPI-2 library with thread support and then rebuild FLASH.
We record extra version and runtime information in the FLASH log file for a threaded application. Table 5.7 shows log file entries from a threaded FLASH application along with example safe and unsafe values. All cells colored red show unsafe values.
The FLASH applications in Table 5.7 are unsafe because
OPENMP_FORTRAN = -openmp -D_OPENMP=200805
You should not setup a FLASH application with both threadBlockList and threadWithinBlock equal to True - nested OpenMP parallelism is not supported. For further information about FLASH multithreaded applications please refer to Chapter 43.