Open MPI logo

Open MPI User's Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Open MPI User's mailing list

Subject: Re: [OMPI users] Help on Mpi derived datatype for class with static members
From: Riccardo Murri (riccardo.murri_at_[hidden])
Date: 2010-12-13 08:42:02


Hi,

On Fri, Dec 10, 2010 at 2:51 AM, Santosh Ansumali <ansumali_at_[hidden]> wrote:
>> - the "static" data member is shared between all instances of the
>>  class, so it cannot be part of the MPI datatype (it will likely be
>>  at a fixed memory location);
>
> Yes! I agree that i is global as far as different instances of class
> is concern.   I don't even want it to be part of MPI datatype.
> However, I am concern
> that as the given class has a static member,  is it ok to just ignore
> its existence while creating MPI datatype?
>

It *should* be. However, an authoritative answer requires good
knowledge of the C++ standard and extensive experience with the
compiler (none of which I personally have), so my suggestion would be
to post the question on comp.lang.c++ or StackOverflow.

>> - in addition, the "i" member is "static const" of a POD type, meaning
>>  the compiler is allowed to optimize it out and not allocate any
>>  actual memory location for it;
>>
>> This boils down to: the only data you need to send around in a "class
>> test" instance is the "double data[5]" array.
>
> True! on what computers there is no memory allocation for static const
> int member.

As far as I understand it, the "const" is a hint to the compiler that
the value will never change, so the storage *could* be optimized out.
Whether this happens or not, depends on the compiler and the
optimization level (e.g., GCC will never optimize a value out with
-O0, but can do it at -O2), and on the actual code as well: if your
code references "&i" at some point, then the compiler has to create
actual storage for "i".

> True! I just want to show the essential part of the class.  The real
> class is inheriting from other class which has no data member.

Beware: if you are using virtual functions in any class of the
hierarchy, then the vtable pointer will be a hidden field in the
class' storage, and you definitely do not want to overwrite it -- this
can influence the start address and/or the displacement of the data.
In a simple case like "class test { double data[5]; }" you can just
use "&data" as the address of your MPI data, but things may be
different in the general case. Again, my adivce would be to post a
question in a dedicated C++ forum for a comprehensive answer.

If you are going to send C++ classes via MPI, you might want to have a
look at Boost.MPI, which provides an easier interface to sending C++
classes around, possibly at some performance and/or memory cost.

Best regards,
Riccardo