I'm working on some code which requires me to send arrays of complex
numbers from a processor to a different processor. The array is
received
successfully at the other end but still it gives some
segmentation faults.
For example, in the following code, I send an
array of size 64 from
processor 0 (master processor) to processor 1.
If i print the data received
at processor 1, it prints successfully.
But the code exits giving
segmentation faults (as listed below this
code). Could you please give me
some pointers to solve this problem.
Thank you in advance.
-rohit
#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#define TEST 1
#define PRINT(A,k,LL) for(k=0;k<LL;k++)\
{\
print_complex(A[k]);\
fflush(stdout);\
int main(int argc, char **argv)
{
int
myrank,nprocs;
int tag0=10;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
MPI_Barrier(MPI_COMM_WORLD);
if(myrank==0)
{
int i=0;
Complex *input_to_p0 =
(Complex*)malloc(SIZE*sizeof(Complex));
for(i=0;i<SIZE;i++)
{
input_to_p0[i][0] = (float)(4*i);
input_to_p0[i][1] = (float)(4*i);
}
MPI_Send(input_to_p0,SIZE,MPI_2COMPLEX,1,tag0,MPI_COMM_WORLD);
free(input_to_p0);
}
else if(myrank == 1)
{
int i=0;
Complex *input_from_p0 = (Complex*)malloc(SIZE*sizeof(Complex));
//Receive the array
from processor 0 (of size SIZE)
MPI_Recv(input_from_p0,SIZE,MPI_2COMPLEX,
0,tag0,MPI_COMM_WORLD,MPI_STATUS_IGNORE);
#if !TEST
printf("\n input receiverd from p0 (I
am in p1) \n");
PRINT(input_from_p0,i,SIZE);
FLUSH;
//received successfully
#endif
free(input_from_p0);
}
MPI_Finalize();
return 0;
[abhogi:03371] *** Process received signal ***
[abhogi:03371] Signal:
Segmentation fault (11)
[abhogi:03371] Signal code: Address not mapped (1)
[abhogi:03371] Failing at address: 0xfd7258
[abhogi:03371] [ 0]
[0xcbe440]
[abhogi:03371] [ 1] /opt/openmpi/lib/libopen-pal.so.0(free+0xb4)
[0x138004]
[abhogi:03371] [ 2] bin/fft(main+0x121) [0x8049461]
[abhogi:03371] [ 3] /lib/libc.so.6(__libc_start_main+0xdc) [0x17af2c]
[abhogi:03371] [ 4] bin/fft [0x80488f1]
[abhogi:03371] *** End of error
message ***
mpirun noticed that job rank 0 with PID 13726 on node saveri
exited on
signal 15 (Terminated).
1 additional process aborted (not
shown)
{where abhogi and saveri are the names of the two computers I am
interacting}