<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-text-flowed" 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 class="moz-txt-link-rfc2396E"
href="http://computing.llnl.gov/tutorials/mpi/#Derived_Data_Types">"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>
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
class="moz-txt-link-abbreviated"
href="http://www.mcs.anl.gov/research/projects/mpi/www/www3/MPI_Type_struct/html">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>
</body>
</html>