Blame view

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