<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix"><tt>Thank you again, Dries! You were
        extremely helpful. I will take a look at the MPI standard.</tt><tt><br>
      </tt><tt><br>
      </tt><tt>Cheers,</tt><tt><br>
      </tt><tt>Helvio</tt><tt><br>
      </tt><tt><br>
      </tt><tt><br>
      </tt><tt>On 12/12/2012 08:22 PM, Dries Kimpe wrote:</tt><tt><br>
      </tt></div>
    <blockquote cite="mid:20121212202211.GA7490@today.mcs.anl.gov"
      type="cite">
      <pre wrap="">
* Hélvio Vairinhos <a class="moz-txt-link-rfc2396E" href="mailto:helvio.vairinhos@gmail.com"><helvio.vairinhos@gmail.com></a> [2012-12-12 20:00:28]:

</pre>
      <blockquote type="cite">
        <pre wrap="">Thanks for your suggestion, Dries! It works if I use &p.elem[0] as the
initial address (not &p->elem), and only if I make elem public.I guess
that's a price to pay (well, I can always fetch the address with a getter).
</pre>
      </blockquote>
      <pre wrap="">
</pre>
      <blockquote type="cite">
        <pre wrap="">Do you know what happens to the memory layout in the presence of virtual
functions if I have multiple components? For example:
</pre>
      </blockquote>
      <pre wrap="">
</pre>
      <blockquote type="cite">
        <pre wrap="">    double a,b;
</pre>
      </blockquote>
      <pre wrap="">
</pre>
      <blockquote type="cite">
        <pre wrap="">instead of:
</pre>
      </blockquote>
      <pre wrap="">
</pre>
      <blockquote type="cite">
        <pre wrap="">    double elem[2];
</pre>
      </blockquote>
      <pre wrap="">
When you have virtual functions (in fact, according to the <C++98
standard, as soon as you have non-trivial constructor/destructor), you can
no longer reason about the memory layout of the struct/class.

They are no longer PODs (plain old datatype).

</pre>
      <blockquote type="cite">
        <pre wrap="">Is it safe to assume that &p.a would give the initial address of a
contiguous structure? Or should I play safe and use MPI_Pack and MPI_Unpack,
for example?
</pre>
      </blockquote>
      <pre wrap="">
Even for a 'contiguous' structure (such as POD struct) the compiler is
allowed to insert padding for alignment reasons. 
The difference with non-POD is that you are allowed to copy those bytes as
well to another instance and expect everything to work.

(i.e. memcpy (&a, &b, sizeof(a)) is allowed for POD).

Really, this is a larger topic. If I'm not mistaken, there is some
discussion of this in the MPI standard, even though at this point, your
question is more a C/C++ question than an MPI question.

To give you at least some practical advice: POD types will generally work
as expected. But I would strongly recommend against making similar
assumptions for non-POD types (i.e. types having public/protect/private
modifiers, non-trivial constructors/destructors, and especially virtual
functions).

  Dries
</pre>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
discuss mailing list     <a class="moz-txt-link-abbreviated" href="mailto:discuss@mpich.org">discuss@mpich.org</a>
To manage subscription options or unsubscribe:
<a class="moz-txt-link-freetext" href="https://lists.mpich.org/mailman/listinfo/discuss">https://lists.mpich.org/mailman/listinfo/discuss</a></pre>
    </blockquote>
    <br>
  </body>
</html>