On Thu, Apr 12, 2012 at 4:37 PM, Zhenglun (Alan) Wei <span dir="ltr"><<a href="mailto:zhenglun.wei@gmail.com">zhenglun.wei@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
<div style="font-family:-moz-fixed;font-size:14px" lang="x-western">Dear All,
<br>
I hope you're having a nice day.
<br>
I came across a problem while using MPI derived data type.
Although it does not related to PETSc, I hope you guys can give me
some suggestions or comments.
<br>
The reason I want to do this is that, in my PETSc code, I
want to send a set of data. It is fairly easy to do that if data
is contiguous; while it would be comparatively hard if it is not.
I searched online and found the MPI derived data type may help me.
What I learned are MPI_TYPE_CONTIGUOUS, MPI_TYPE_VECTOR and
MPI_TYPE_STRUCT. I did a test program, which basically combined
several example programs in <a href="http://computing.llnl.gov/tutorials/mpi/#Derived_Data_Types" target="_blank">"http://computing.llnl.gov/tutorials/mpi/#Derived_Data_Types"</a>
with all these three MPI derived data types. It works fine.
(Please see my attachment for AlanFloatStruct.c). Briefly saying,
it generates a 4 by 4 matrix 'a[i][j]', where 'a' is a structure
with members of 'u' and 'v':
<br>
<br>
a[i][j].u is
<br>
01 02 03 04 // 2 digits just for E-mail format.
Actually, you may find that data type for member '.u' is 'double'
<br>
05 06 07 08
<br>
09 10 11 12
<br>
13 14 15 16
<br>
a[i][j].v = 10*a[i][j].u // I will neglect .v later, because I
want to focus on .u member
<br>
<br>
As I defined, 'j' in 'a[i][j]' is the inner loop. For
example, a[0][0] = 1, a[0][1] = 2, a[0][2] = 3 ... So, they are
contiguous. Then, 'i' is the outer loop, a[0][0] = 1, a[1][0] = 5
..., which are not contiguous. <br>
My purpose is let rank = 0 to send the 4 contiguous data of
a[n][m] (m = 0~3) to n'th rank and store them to 'b[n][p]' in the
n'th rank. Then, I want to send the 4 non-contiguous data of
a[m][n] (m = 0~3) to n'th rank and store them to 'c[p][n]' in the
n'th rank. For example, if 'b' and 'c' are 4 by 4 matrix and
initialized by '-5', after communication with rank = 0, I expect
in rank = 1
<br>
<br>
b[i][j].u
<br>
-5 -5 -5 -5
<br>
05 06 07 08
<br>
-5 -5 -5 -5
<br>
-5 -5 -5 -5
<br>
c[i][j].v
<br>
-5 02 -5 -5
<br>
-5 06 -5 -5
<br>
-5 10 -5 -5
<br>
-5 14 -5 -5
<br>
<br>
Everything is fine in AlanFloatStruct.c. <b>However, when I
was trying to use 'calloc' to allocate memory to 'a[][]' rather
than directly define 'a[][]' as a structure matrix, the problem
comes.</b> (see AlanTEST1.c). 'b' matrix is ok, yet, it keeps
giving me problems for 'c' that
<br>
</div></div></blockquote><div><br></div><div>If you declare c[][] on the stack, most compilers will lay it out contiguously. However, if you separately allocate each row, they</div><div>need not be contiguous. If you really want to do this, allocate one big block, and setup the pointers to each row yourself.</div>
<div><br></div><div> Thanks,</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div bgcolor="#FFFFFF" text="#000000">
<div style="font-family:-moz-fixed;font-size:14px" lang="x-western">c[i][j].u
<br>
-5 02 -5 -5
<br>
-5 00 -5 -5
<br>
-5 00 -5 -5
<br>
-5 00 -5 -5
<br>
<br>
I guess it would be some problem for byte counting or padding
of MPI data in 'calloc'. I refer to 'Notes' part in '<a href="http://www.mcs.anl.gov/research/projects/mpi/www/www3/MPI_Type_struct/html" target="_blank">www.mcs.anl.gov/research/projects/mpi/www/www3/MPI_Type_struct/html</a>'
and made AlanTEST2.c. The problem is still there.
<br>
I wonder what should I for this? Or, does PETS have any
alternative way to fix this problem. BTW, if you want to run my
code, you need change the name of .c file to AlanTEST.c. My script
file 'AlanRun' is written based on AlanTEST.c.
<br>
<br>
thank you so much in advance,
<br>
Alan
<br>
<br>
</div>
</div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener<br>