List Info

Thread: LAM: Question using MPI with C++




LAM: Question using MPI with C++
country flaguser name
Germany
2007-09-29 13:36:18
Hello,

i'm still very new to MPI. I want to use it within my C++
code. 
I'm wondering why for example the Send(..) or Recv(..)
routines in C do have an bool return value
and in C++ are void. 

In C i used to write something like this:
if (MPI_Recv(static_cast<void*> (&tmp), 1,
MPI_INT, 
		0, tag, world, &status))
		//abort programm or do something

Now how should i do this in C++? 

Perhaps something like that?
try
	 {
	   MPI::COMM_WORLD.Recv(&n, 1, MPI::INT,
MPI::ANY_SOURCE, MPI::ANY_TAG, status);
	 }
	 catch(MPI::Exception e) 
         {
          ...//do something
         }

is this the usual way or do i forget something?

Thanks for help
____________________________________________________________
_________
Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten
zu sparen!
http://smartsurfer.web.de/?mc=100071&dis
tributionid=000000000066

_______________________________________________
This list is archived at http://www.l
am-mpi.org/MailArchives/lam/

Re: LAM: Question using MPI with C++
country flaguser name
United States
2007-09-29 22:58:38
On Sep 29, 2007, at 12:36 PM, XMATXweb.de wrote:

> i'm still very new to MPI. I want to use it within my
C++ code.
> I'm wondering why for example the Send(..) or Recv(..)
routines in  
> C do have an bool return value
> and in C++ are void.
>
> Now how should i do this in C++?
>
> Perhaps something like that?
> try
> 	 {
> 	   MPI::COMM_WORLD.Recv(&n, 1, MPI::INT,
MPI::ANY_SOURCE,  
> MPI::ANY_TAG, status);
> 	 }
> 	 catch(MPI::Exception e)
>          {
>           ...//do something
>          }
>
> is this the usual way or do i forget something?

By default (for both C and C++), errors on MPI communication
will  
case MPI to abort.  So unless you're resetting the error
handler on  
the communicator in use, there's no need to check error
conditions at  
all.  However, if you are (or plan to) reset the error
handler, the C+ 
+ bindings throw exceptions on errors.  So your example
would be  
correct.

There is nothing that says you should use the C++ MPI
bindings if you  
are writing C++ code.  A high percentage of the C++ codes I
deal with  
use the C bindings to MPI.  If you are more comfortable with
the C  
bindings to MPI, by all means use them.  There are few
advantages to  
using the C++ bindings, and there can be a number of
disadvantages.


Hope this helps,

Brian

_______________________________________________
This list is archived at http://www.l
am-mpi.org/MailArchives/lam/

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )