Parallel Programming with O2scl =============================== :ref:`O2scl ` Parallel contents ----------------- - :ref:`Thread safety and parallelism` - :ref:`OpenMP and O2scl` - :ref:`MPI and O2scl` Thread safety and parallelism ----------------------------- Generally, O₂scl objects are thread-safe in the same way that classes like ``std::vector`` 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 :ref:`table ` functions and to test the multithreaded behavior of :ref:`anneal_para `, :ref:`mcmc_para_base `, and :ref:`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=ⅇ // Do stuff here MPI_Finalize(); return 0; } You can test to see if OpenMP support was enabled during installation in the :cpp:var:`o2scl::o2scl_settings` object of type :ref:`lib_settings_class ` or with ``acol -v``. MPI and O2scl ------------- Currently, all MPI calls are in header classes. MPI functions are used in :ref:`anneal_para `, :ref:`mcmc_para_base `, and :ref:`mcmc_para_table `. An MPI-friendly tool for seeding random number generators is provided in :cpp:func:`o2scl::rng_set_seed_mpi()`. .. You can test to see if MPI support was enabled during installation in the \ref o2scl::o2scl_settings object of type \ref o2scl::lib_settings_class or with ``acol -v``.