LAM/MPI logo

LAM/MPI General User's Mailing List Archives

  |   Home   |   Download   |   Documentation   |   FAQ   |   all just in this list

From: Nick Nevin (njnevin_at_[hidden])
Date: 2003-08-19 06:25:51


On Tue, Aug 19, 2003 at 10:12:40AM +0100, Klein, Bernhard wrote:
> Hi MPI-Folks,
>
> I'm a newbie in MPI and have the following problem:
> Thow processes are connected with MPI_Connect, etc.
> I will transfer a struct from one process to the rank 0 process, but I got
> nothing at rank 0 process
> I defined following
>
> ####################################################
> # defining the structure for transfer
> ####################################################
>
> #define MAX_PARAMETER_SIZE 128
> #define MAX_PARAMETER 8
> #define MPILOGGER_COUNT 7
>
> typedef struct {
> int msgno ;
> int pid ;
> int rank ;
> int instance ;
> int count ;
> char logfilename [MAX_PARAMETER_SIZE] ;
> char parameter[MAX_PARAMETER][MAX_PARAMETER_SIZE] ;
>
> } MPIStruct ;
>
> MPIStruct mpiStruct ;
>
> MPI_Aint mpiDatatypeAddress ;
> MPI_Aint DTComponents[MPILOGGER_COUNT] ;
> int DTLength[MPILOGGER_COUNT] ;
> MPI_Datatype DTTypes[MPILOGGER_COUNT] ;
> MPI_Datatype mpiDatatype ;
>
> ####################################################
> # Defining the new MPI-Datatype
> ####################################################
>
> mpiDatatypeAddress = MPI::Get_address ( &mpiDatatype) ;
>
> DTComponents[0] = MPI::Get_address ( &mpiStruct.msgno ) ;
> DTComponents[1] = MPI::Get_address ( &mpiStruct.pid ) ;
> DTComponents[2] = MPI::Get_address ( &mpiStruct.rank ) ;
> DTComponents[3] = MPI::Get_address ( &mpiStruct.instance ) ;
> DTComponents[4] = MPI::Get_address ( &mpiStruct.count ) ;
> DTComponents[5] = MPI::Get_address ( &mpiStruct.logfilename ) ;
> DTComponents[6] = MPI::Get_address ( &mpiStruct.parameter ) ;
>
> DTComponents[0] -= mpiDatatypeAddress ;
> DTComponents[1] -= mpiDatatypeAddress ;
> DTComponents[2] -= mpiDatatypeAddress ;
> DTComponents[3] -= mpiDatatypeAddress ;
> DTComponents[4] -= mpiDatatypeAddress ;
> DTComponents[5] -= mpiDatatypeAddress ;
> DTComponents[5] -= mpiDatatypeAddress ;
> DTComponents[6] -= mpiDatatypeAddress ;
>

The displacements for the MPI struct type should be offsets from the
beginning of the C struct it is to represent. They have no relationship
to the address of the variable used for the datatype handle. Replace the
last 7 lines above with.

        for (i=6; i>=0; i--)
                DTComponents[i] -= DTComponents[0];

You may find the examples in chapter 3.12 of the MPI 1.1 standard
useful.

Good luck, Nick.