LAM/MPI logo

LAM/MPI General User's Mailing List Archives

  |   Home   |   Download   |   Documentation   |   FAQ   |   all just in this list

From: Brian W. Barrett (brbarret_at_[hidden])
Date: 2002-09-30 10:44:36


On Mon, 30 Sep 2002, Chien-Yu Chen wrote:

> I have a general question that I don't seem to find the correct example
> to use.
>
> most examples uses something like
>
> struct {
> int a;
> float b;
> }
>
> to construct a new type...but I am trying to use some type that's not
> standard, ie, the ZZ type from ntl (an arbitrary long integer)...
> Can someone point me to an example with user defined type? thanks

The NTL library is a C++ library, and the ZZ type is a class. Which is
problematic for what you are trying to do. The MPI standard (even the C++
bindings) provide methods for sending plain old datatypes (PODs) and,
using the mpi_type_struct or friends functions, fairly simple structs.

However, there are two things that the MPI datatype system is really bad
at handling: C++ objects and pointers in structures. For the second, as
has been mentioned on the list before, you really have to explicitly
follow the pointer in user code - MPI won't do it for you. For the first,
there is not really anything you can do - there aren't good, portable ways
to serialize a C++ object.

So, where does that leave you? Well, you can violate the abstraction
barriers that NTL tries to put up and figure out what data from the object
you need to send around. And then update your code every time NTL chanes
the ZZ object. Or, and I'm sure this won't be the best performance
option, you can take advantage of the operator<<(ostream&, ...) and
operator>>(istream&, ...) functions to serialize into a stream, dump that
into a string, get the char* array from that, and call MPI_SEND to send
that char* around. Then reverse that whole thing to get the number back
into a ZZ object. Hardly space or time efficient, but the interface will
always be the same :).

Hope this helps,

Brian

-- 
  Brian Barrett
  LAM/MPI developer and all around nice guy
  Have a LAM/MPI day: http://www.lam-mpi.org/
_______________________________________________
This list is archived at http://www.lam-mpi.org/MailArchives/lam/