|
Boost Users : |
Subject: Re: [Boost-users] mpi non-blocking communication
From: Riccardo Murri (riccardo.murri_at_[hidden])
Date: 2010-12-06 17:31:59
Hi Hicham,
On Mon, Dec 6, 2010 at 11:58 AM, Hicham Mouline <hicham_at_[hidden]> wrote:
>> (1) You must initialize MPI with MPI_Init_thread() instead of
>>MPI_Init(). Â The boost::mpi::communicator ctor uses MPI_Init(), so you
>>must run the initialization yourself and *then* create the
>>communicator object. Â For instance::
>>Â Â Â MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED)
>>Â Â Â // ...
>>Â Â Â mpi::communicator world;
>
> I have the following code in my main:
>
> int main(int argc, char* argv[])
> {
> Â boost::mpi::environment env(argc, argv);
> Â const int mpi_thread_support = MPI::Init_thread(argc, argv, MPI_THREAD_SERIALIZED );
> Â if (mpi_thread_support != MPI_THREAD_SERIALIZED)
> Â {
> Â Â std::cerr<< "MPI implementation does not support threads" <<std::endl;
> Â Â return 1;
> Â }
> Â boost::mpi::communicator world;
> ...
> }
>
> This prints an error however:
>
> Calling MPI_Init or MPI_Init_thread twice is erroneous.
>
> How does 1 avoid that the mpi::communicator constructor calling MPI_INIT twice?
>
> Perhaps it's the environment constructor that calls MPI_INIT?
>
Yes, indeed. There's a mistake in the pseudo-code I sent in my reply
to Philipp: one must call MPI_Init_thread() before istanciating
boost::mpi::environment. So the correct init order is:
MPI_Init_thread(&argc, &argv, required, &provided);
if (required > provided) {
// warning: MPI impl does not support the requested threading model
}
mpi::environment env(argc, argv);
mpi::communicator world;
Thanks for the correction!
Best regards,
Riccardo
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net