afb0d1460a
Put thread doc in its own file
36 lines
1.2 KiB
Plaintext
36 lines
1.2 KiB
Plaintext
[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]
|