Discussion:
[OMPI users] MPI_Type_create_struct segfault
George Reeke
2017-01-30 21:31:34 UTC
Permalink
Dear colleagues,
I am trying MPI_Type_create_struct for the first time.
I want to combine a small structure (two ints) with a vector of
variable length to send in a single message. Here is a simplified
extract of the relevant C code. The MPI_Type_create_struct call
gives a segfault. The nearest I can see to what is wrong is that
the argument I called GHtyp has as its first element a small
integer (0x53) which the function ompi_datatype_create_struct
is trying to use as a pointer. But I thought I created it with
an MPI_Type_contiguous call:

/* The next three variables are passed in from other
* calculations and have reasonable values per gdb. */
char *pv = /* Pointer to my data array */
int lblk = /* Length of one element of my data array */
int nblks = /* Number of these blocks in the data vector */
MPI_Datatype MPHdr,MPBlk,MPPkt;
struct GHdr_t {
int odat, nblk; /* Code to set these values not shown */
} sGHdr;
int GHect[2] = { 1, 0 }; /* Second count inserted below */
MPI_Datatype GHtyp[2] = { MPHdr, MPBlk };
MPI_Aint GHoff[2];
/* Executable code */
MPI_Type_contiguous(2, MPI_UNSIGNED, &MPHdr);
MPI_Type_commit(&MPHdr);
MPI_Type_contiguous(lblk, MPI_UNSIGNED_CHAR, &MPBlk);
MPI_Type_commit(&MPBlk);
GHect[1] = nblks;
MPI_Get_address(pv, GHoff+1);
MPI_Get_address(&sGHdr, GHoff);
MPI_Type_create_struct(2, GHect, GHoff, GHtyp, &MPPkt);
----segfault on this call-never gets to the following commit----

Any suggestions would be most welcome.
Thanks,
George Reeke
Gilles Gouaillardet
2017-01-31 00:07:33 UTC
Permalink
George,


at first glance, it seems GHtyp is initialized too early with

uninitialized types MPHdr and MPBlk.


can you try to initialize GHtyp *after* both types are commited ?


if it still does not work, could you please post a self contained and
simple reproducer ?


Cheers,


Gilles
Post by George Reeke
Dear colleagues,
I am trying MPI_Type_create_struct for the first time.
I want to combine a small structure (two ints) with a vector of
variable length to send in a single message. Here is a simplified
extract of the relevant C code. The MPI_Type_create_struct call
gives a segfault. The nearest I can see to what is wrong is that
the argument I called GHtyp has as its first element a small
integer (0x53) which the function ompi_datatype_create_struct
is trying to use as a pointer. But I thought I created it with
/* The next three variables are passed in from other
* calculations and have reasonable values per gdb. */
char *pv = /* Pointer to my data array */
int lblk = /* Length of one element of my data array */
int nblks = /* Number of these blocks in the data vector */
MPI_Datatype MPHdr,MPBlk,MPPkt;
struct GHdr_t {
int odat, nblk; /* Code to set these values not shown */
} sGHdr;
int GHect[2] = { 1, 0 }; /* Second count inserted below */
MPI_Datatype GHtyp[2] = { MPHdr, MPBlk };
MPI_Aint GHoff[2];
/* Executable code */
MPI_Type_contiguous(2, MPI_UNSIGNED, &MPHdr);
MPI_Type_commit(&MPHdr);
MPI_Type_contiguous(lblk, MPI_UNSIGNED_CHAR, &MPBlk);
MPI_Type_commit(&MPBlk);
GHect[1] = nblks;
MPI_Get_address(pv, GHoff+1);
MPI_Get_address(&sGHdr, GHoff);
MPI_Type_create_struct(2, GHect, GHoff, GHtyp, &MPPkt);
----segfault on this call-never gets to the following commit----
Any suggestions would be most welcome.
Thanks,
George Reeke
_______________________________________________
users mailing list
https://rfd.newmexicoconsortium.org/mailman/listinfo/users
George Reeke
2017-01-31 15:38:46 UTC
Permalink
Dear Gilles et al,
You are correct. I solved the problem based on an email I got
privately based on the same idea. I have just posted that private
reply so the solution will be more widely known among us amateurs.
Thanks,
George Reeke
Post by Gilles Gouaillardet
George,
at first glance, it seems GHtyp is initialized too early with
uninitialized types MPHdr and MPBlk.
can you try to initialize GHtyp *after* both types are commited ?
if it still does not work, could you please post a self contained and
simple reproducer ?
Cheers,
Gilles
Post by George Reeke
Dear colleagues,
I am trying MPI_Type_create_struct for the first time.
I want to combine a small structure (two ints) with a vector of
variable length to send in a single message. Here is a simplified
extract of the relevant C code. The MPI_Type_create_struct call
gives a segfault. The nearest I can see to what is wrong is that
the argument I called GHtyp has as its first element a small
integer (0x53) which the function ompi_datatype_create_struct
is trying to use as a pointer. But I thought I created it with
/* The next three variables are passed in from other
* calculations and have reasonable values per gdb. */
char *pv = /* Pointer to my data array */
int lblk = /* Length of one element of my data array */
int nblks = /* Number of these blocks in the data vector */
MPI_Datatype MPHdr,MPBlk,MPPkt;
struct GHdr_t {
int odat, nblk; /* Code to set these values not shown */
} sGHdr;
int GHect[2] = { 1, 0 }; /* Second count inserted below */
MPI_Datatype GHtyp[2] = { MPHdr, MPBlk };
MPI_Aint GHoff[2];
/* Executable code */
MPI_Type_contiguous(2, MPI_UNSIGNED, &MPHdr);
MPI_Type_commit(&MPHdr);
MPI_Type_contiguous(lblk, MPI_UNSIGNED_CHAR, &MPBlk);
MPI_Type_commit(&MPBlk);
GHect[1] = nblks;
MPI_Get_address(pv, GHoff+1);
MPI_Get_address(&sGHdr, GHoff);
MPI_Type_create_struct(2, GHect, GHoff, GHtyp, &MPPkt);
----segfault on this call-never gets to the following commit----
Any suggestions would be most welcome.
Thanks,
George Reeke
_______________________________________________
users mailing list
https://urldefense.proofpoint.com/v2/url?u=https-3A__rfd.newmexicoconsortium.org_mailman_listinfo_users&d=DwICAg&c=JeTkUgVztGMmhKYjxsy2rfoWYibK1YmxXez1G3oNStg&r=-0HYJje2XxONzoGLV3ECU5R_Z00xayE_1fNBml0KNOw&m=6jcjTW1w8vADLHM-UQbR1V8MmPVUF0b3eL0lVXih2FU&s=EW16AGT-1oxU0wl0DgK9ojoH4lfD4_UmrMCFGg8q7MM&e=
_______________________________________________
users mailing list
https://urldefense.proofpoint.com/v2/url?u=https-3A__rfd.newmexicoconsortium.org_mailman_listinfo_users&d=DwICAg&c=JeTkUgVztGMmhKYjxsy2rfoWYibK1YmxXez1G3oNStg&r=-0HYJje2XxONzoGLV3ECU5R_Z00xayE_1fNBml0KNOw&m=6jcjTW1w8vADLHM-UQbR1V8MmPVUF0b3eL0lVXih2FU&s=EW16AGT-1oxU0wl0DgK9ojoH4lfD4_UmrMCFGg8q7MM&e=
George Reeke
2017-01-31 15:34:50 UTC
Permalink
Post by George Reeke
Dear colleagues,
I am trying MPI_Type_create_struct for the first time.
I want to combine a small structure (two ints) with a vector of
variable length to send in a single message. Here is a simplified
extract of the relevant C code. The MPI_Type_create_struct call
gives a segfault.
----code sample snipped, see original posting if interested----
Post by George Reeke
Any suggestions would be most welcome.
Thanks,
George Reeke
I just wanted to share with everyone a reply that I received offline
to my original posting. Bottom line: I needed to copy the result
of an MPI create type into handle lists where it was used, not just
put the name there. In my case I was creating a structured type,
members of which were previously defined structure types.
(I have removed the name of the person who replied privately since
I do not know if posting it would be a problem.)
George Reeke
Post by George Reeke
Hi George,
George Reeke wrote on Tue, 31 Jan 2017 at 10:31:34
<snip...>
Post by George Reeke
MPI_Datatype GHtyp[2] = { MPHdr, MPBlk };
Note that GHtyp is initialized with uninitialized data in MPHdr and
MPBlk (i.e. garbage)
Post by George Reeke
<snip...>
Post by George Reeke
MPI_Type_contiguous(2, MPI_UNSIGNED, &MPHdr);
This sets MPHdr, but does not update GHtyp[0]. Replace '&MPHdr' with
'&GHtyp[0]'.
Post by George Reeke
Post by George Reeke
MPI_Type_commit(&MPHdr);
MPI_Type_contiguous(lblk, MPI_UNSIGNED_CHAR, &MPBlk);
This sets MPBlk, but does not update GHtyp[1]. Replace '&MPBlk' with
'&GHtyp[1]'.
Post by George Reeke
<snip...>
Post by George Reeke
MPI_Type_create_struct(2, GHect, GHoff, GHtyp, &MPPkt);
GHtyp still contains garbage here, leading to your segfault.
Loading...