Parallel Programming with O2scl

O2scl

Parallel contents

Thread safety and parallelism

Generally, O₂scl objects are thread-safe in the same way that classes like std::vector<double> are thread-safe: reads are safe and writes are unsafe. It may be useful to make objects const to ensure that one is reading data in a thread-safe way. O₂scl is designed to ensure const methods are thread-safe, unless noted. (A few classes contain mutable internal members which mean that const methods are not thread-safe, and this is noted in the class documentation.)

OpenMP and O2scl

OpenMP support may be enabled during installation by --enable-openmp. OpenMP support during installation allows O₂scl to use parallelism to speed up some table functions and to test the multithreaded behavior of anneal_para, mcmc_para_base, and mcmc_para_table.

On some systems, code similar to the following may be required to ensure that the error handler is valid on each OpenMP thread:

int main(int argc, char *argv[]) {
  cout.setf(ios::scientific);
  MPI_Init(&argc,&argv);
  // Create a new error handler for this thread
  o2scl::err_hnd_cpp ee;
  o2scl::err_hnd=&ee;
  // Do stuff here
  MPI_Finalize();
  return 0;
}

You can test to see if OpenMP support was enabled during installation in the o2scl::o2scl_settings object of type lib_settings_class or with acol -v.

MPI and O2scl

Currently, all MPI calls are in header classes. MPI functions are used in anneal_para, mcmc_para_base, and mcmc_para_table. An MPI-friendly tool for seeding random number generators is provided in o2scl::rng_set_seed_mpi().