Hi!
I am trying to create a dynamic buffer for the data I will communicate. I
want to communicate a struct. so I used MPI_Type_struct. what I am trying to
do is to make each elemant to be an array where the size of the array is
dynamic. but the process which tries to send the message recive a error
signal. here is the error message. please advise me with what I am doing
wrong, or of a better way to do the dynamic buffer.
Best Regards
Sherif
MPI process rank 0 (n0, p15810) caught a SIGSEGV in MPI_Isend.
Rank (0, MPI_COMM_WORLD): Call stack within LAM:
Rank (0, MPI_COMM_WORLD): - MPI_Isend()
Rank (0, MPI_COMM_WORLD): - main()
-----------------------------------------------------------------------------
One of the processes started by mpirun has exited with a nonzero exit
code. This typically indicates that the process finished in error.
If your process did not finish in error, be sure to include a "return
0" or "exit(0)" in your C code before exiting the application.
PID 15810 failed on node n0 with exit status 1.
-----------------------------------------------------------------------------
/********************* here is my Code ***************/
#include "mpi.h"
#include <stdio.h>
#include <cstring>
#include <iostream.h>
/******************************/
/* function to create my struct */
void Build_derived_type(double * a_ptr,double * b_ptr,int* n_ptr,
MPI_Datatype* mesg_mpi_t_ptr)
{//start Build_derived_type
int block_lengths[3];
MPI_Aint displacements [3];
MPI_Datatype typelist[3];
MPI_Aint start_address;
MPI_Aint address;
block_lengths[0]= block_lengths[1]= 10;
block_lengths[2]=1;
typelist[0]=MPI_DOUBLE;
typelist[1]=MPI_DOUBLE;
typelist[2]=MPI_INT;
displacements[0]=0;
MPI_Address (a_ptr,&start_address);
MPI_Address(b_ptr,&address);
displacements [1]=address - start_address;
MPI_Address(n_ptr,&address);
displacements[2]= address - start_address;
MPI_Type_struct(3,block_lengths,displacements,typelist,mesg_mpi_t_ptr);
MPI_Type_commit(mesg_mpi_t_ptr);
}//end Build_derived_type
/********************************/
int main (int argc, char *argv[])
{//start main
int numprocs, myrank, namelen,i,n;
// double *A,* B;
MPI_Datatype mytype;
MPI_Request Reqs;
char processor_name[MPI_MAX_PROCESSOR_NAME];
char greeting [MPI_MAX_PROCESSOR_NAME + 80];
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
MPI_Get_processor_name (processor_name, &namelen);
/* pointer to an array */
double * A=new double [10];double * B = new double [10];
Build_derived_type (A,B,&myrank,& mytype);
if (myrank ==0){
for (i=0; i<10;i++){A[i]=(double)i;B[i]=(double)i+10;}
for (i=0; i<10;i++) cout << "A [ "<<i <<" ] = "<< A[i]<<" **** B [ "
<<i<< " ]= "<< B[i]<< endl ;
MPI_Isend(A, sizeof(mytype),mytype,1,1,MPI_COMM_WORLD,&Reqs);
MPI_Wait(&Reqs,&status);
}
else if (myrank ==1){
MPI_Irecv(A,sizeof(mytype),mytype,0,1,MPI_COMM_WORLD,&Reqs);
MPI_Wait (&Reqs,&status);
for (i=0; i<10;i++) cout << "A [ "<<i <<" ] = "<< A[i]<<" **** B [ "
<<i<< " ]= "<< B[i]<< endl ;
}
MPI_Finalize();
return (0);
}//end main
_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail
|