• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[section:threading Threads]
2
3There are an increasing number of hybrid parallel applications that mix
4distributed and shared memory parallelism. To know how to support that model,
5one need to know what level of threading support is guaranteed by the MPI
6implementation. There are 4 ordered level of possible threading support described
7by [enumref boost::mpi::threading::level mpi::threading::level].
8At the lowest level, you should not use threads at all, at the highest level, any
9thread can perform MPI call.
10
11If you want to use multi-threading in your MPI application, you should indicate
12in the environment constructor your preferred threading support. Then probe the
13one the library did provide, and decide what you can do with it (it could be
14nothing, then aborting is a valid option):
15
16  #include <boost/mpi/environment.hpp>
17  #include <boost/mpi/communicator.hpp>
18  #include <iostream>
19  namespace mpi = boost::mpi;
20  namespace mt  = mpi::threading;
21
22  int main()
23  {
24    mpi::environment env(mt::funneled);
25    if (env.thread_level() < mt::funneled) {
26       env.abort(-1);
27    }
28    mpi::communicator world;
29    std::cout << "I am process " << world.rank() << " of " << world.size()
30              << "." << std::endl;
31    return 0;
32  }
33
34
35[endsect:threading]
36