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: Santosh Ansumali (ansumali_at_[hidden])
Date: 2010-12-09 20:51:33


Thanks every one.

> - 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?

> - 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 stated, one is not even interested in sending static
member.
Thus, just ignoring existence of this static member might work.
However, my question is how to write this code in a generic way. Is
it always guaranteed that an array created from a class consisting of
static member will be contiguous in memory? As I have not seen any MPI
data creation
for a class with static member, I am curious to know what the
standard is before proceeding further. May be a simple example will
do.

> If the static member were not "const", you could send it in a separate
> message.
>
> Best regards,
> Riccardo
>
>
> P.S. Besides, all members in a "class" are private by default and
> "class test" does not have a constructor, so there's no way you can
> put any useful values into this "test" class.  (But I guess this is
> just an oversight when stripping down the code for the example...)
>

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.
template <typename dataType, class INPUT >
 class baseET {
   public:
     typedef const INPUT& INPUT_REF;
     // Return Reference to object T
    operator INPUT_REF () const{
      return static_cast<INPUT_REF> (*this ) ;
   }

   dataType value(const int i) const{
      return static_cast<INPUT_REF> (*this ).value(i) ;
   }
   };

Then after stripping all functions the class is

template <typename dataType, int N>
class vectET :public baseET<dataType, vectET<dataType, N> >
{
  public:
   ........
  private:

         static const int numELEM =N;
    myReal data[numELEM];
};

Further, main code is creating nD array of this class and I want to
create MPI data for exchange of array of such 3D class.

-- 
Santosh Ansumali,
Faculty Fellow,
Engineering Mechanics Unit
Jawaharlal Nehru Centre for Advanced Scientific Research (JNCASR)
 Jakkur, Bangalore-560 064, India
Tel: + 91 80 22082938