First of all with your approach you're not sending all the structure.
You will just send the num_Rocs and the elements, missing the
num_Cols member off the structure. The problem come from the fact
that lena[0] is set to 1 not 2.
Another problem (which I don't think it can happens with this
particular structure) is that we don't know how the compiler will
create the structure in memory. For this particular structure, as you
just use ints I don't think that will be a problem as the alignment
will be correct and no padding should be inserted in order to have
all elements correctly aligned. Anyway, I'll give you a general
example who should work in all cases.
There is another bug in your code. When you create the
MPI_Type_struct you set the count to 1. This count is not the number
of data you plan to send, but the number of elements you describe in
the arrays used to create the type_struct.
george.
PS: Here is a piece of code that do what you expect ... I think ...
struct {
int num_Rows;
int num_Cols;
int element[NELEM];
} send_pack;
send_pack sp[2];
MPI_Datatype typa[3], temp_type, final_type;
MPI_Aint loca[3], origin, extent;
int lena[3];
/* Get the pointer to the sp structure */
MPI_Address( &(sp[0]), &origin );
/* Fill-up the arrays used to create the MPI_Struct */
type[0] = MPI_INT;
lena[0] = 1;
MPI_Address( &(sp[0].num_Rows), &(loca[0]) );
type[1] = MPI_INT;
lena[1] = 1;
MPI_Address( &(sp[0].num_Cols), &(loca[1]) );
type[2] = MPI_INT;
lena[2] = 1;
MPI_Address( &(sp[0].elements[0]), &(loca[2]) );
/* Now compute the correct displacement for the elements. Everything
depend on the origin */
loca[0] -= origin;
loca[1] -= origin;
loca[2] -= origin;
MPI_Type_struct( 3, lena, loca, typa, temp_type );
/* There is just one more thing left. Setting the correct bound for
one element of the structure
* This can be achieved using different ways. The one I prefer is
not MPI 1 specific but MPI-2
* but it's a lot more cleaner and user "friendly" (and I think it
make the code a lot more readable).
* If you want to be MPI-1 specific, you should add one more element
to you array (with the type MPI_UB)
* and the same displacement as in the following code.
*/
MPI_Address( &(sp[1]), &extent );
extent -= origin;
MPI_Type_create_resized( temp_type, (MPI_Aint)0, extent, &final_type );
/* A little bit of cleanup ... */
MPI_Type_free( &temp_type );
/* Here we are. The datatype is correctly set now we just have to
commit it in order to be allowed
* to use it in MPI communications.
*/
MPI_Type_commit( &final_type );
if( my_rank == sender ) {
MPI_Send( &(sp[0]), 1, final_type, receiver, tag, MPI_COMM_WORLD );
} else idd( my_rank == receiver ) {
MPI_Recv( &sp[0]), 1, final_type, sender, tag, MPI_COMM_WORLD,
MPI_STATUS_IGNORE );
} else {
/* blah blah */
}
On Aug 25, 2005, at 11:38 AM, Raul Mosquera wrote:
Hi:
I'm trying to pass an structure which is defined like this
#include <stdio.h>
#include <string.h>
#include "mpi.h"
#define NELEM 6
struct{
int num_Rows;
int num_Cols;
int element[NELEM];
}send_pack;
//num_Rows and num_Cols identify the matrix being passed in the
array element.
// Variable declaration
int rank,size,tag=1,source=0,dest;
MPI_Status status;
int lena[2] ; // This is for the length of the elements holding
MPI_Aint loca[2], extent; //localization
MPI_Datatype typa[2];
MPI_Datatype MY_TYPE;
//MPI_Type_extent(MPI_INT,&extent);
typa[0]=MPI_INT;
typa[1]=MPI_INT;
lena[0]=1;
lena[1]=NELEM;
loca[0]=0;
loca[1]= 2 * extent;
The structure is being created like this
MPI_Type_struct(1,lena,loca,typa,&MY_TYPE);
MPI_Type_commit(&MY_TYPE); //creates the structure
When sending ...
MPI_Send(&send_pack,1,MY_TYPE,1,tag,MPI_COMM_WORLD);
When Receiving
MPI_Recv(&send_pack,1,MY_TYPE,0,tag,MPI_COMM_WORLD,&status);
The program sends the message but it shows errors on the other side.
My guess is that the parameters in the MPI_Send are not declare in
the proper way.
Can you guys help me understandig what I'm doing wrong.
Thanks
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
users mailing list
us...@open-mpi.org
http://www.open-mpi.org/mailman/listinfo.cgi/users