I want to exchange a weatherdata struct between nodes in a grid with MPI_Neighbor_alltoall. My program compiles and runs, but the exchanged data is not correct.
my weatherdata struct
typedef struct s_weatherdata{
// coordinates
float lon;
float lat;
// main
int pressure;
int humidity;
int temp;
// wind
int speed;
int deg;
}weatherdata;
my create cart snippet
// Create Dimensions
MPI_Dims_create(size, ndims, dims);
// Create Cartesian
MPI_Cart_create(mycomm, ndims, dims, periods, 1, &cart_comm);
// Get the name of the processor
char processor_name[MPI_MAX_PROCESSOR_NAME];
int len;
MPI_Get_processor_name(processor_name, &len);
// Get coordinates
MPI_Cart_coords(cart_comm, rank, ndims, coord);
create MPI weatherdata struct
// create a type for weatherdata
const int nitems = 7;
int blocklengths[7] = {1,1,1,1,1,1,1};
MPI_Datatype types[7] = {MPI_FLOAT, MPI_FLOAT, MPI_INT, MPI_INT, MPI_INT, MPI_INT, MPI_INT};
MPI_Datatype tmp_mpi_weatherdata, mpi_weatherdata;
MPI_Aint offsets[7];
MPI_Aint lb, extent;
offsets[0] = offsetof(weatherdata, lon);
offsets[1] = offsetof(weatherdata, lat);
offsets[2] = offsetof(weatherdata, pressure);
offsets[3] = offsetof(weatherdata, humidity);
offsets[4] = offsetof(weatherdata, temp);
offsets[5] = offsetof(weatherdata, speed);
offsets[6] = offsetof(weatherdata, deg);
MPI_Type_create_struct(nitems, blocklengths, offsets, types, &tmp_mpi_weatherdata);
MPI_Type_get_extent(tmp_mpi_weatherdata, &lb, &extent);
MPI_Type_create_resized(tmp_mpi_weatherdata, lb, extent, &mpi_weatherdata);
MPI_Type_commit(&mpi_weatherdata);
weatherdata **recvdata = malloc(4*sizeof(weatherdata *));
weatherdata *data0 = malloc(4*(sizeof(weatherdata)));
weatherdata *data1 = data0+sizeof(weatherdata);
weatherdata *data2 = data1+sizeof(weatherdata);
weatherdata *data3 = data2+sizeof(weatherdata);
recvdata[0]=data0;
recvdata[1]=data1;
recvdata[2]=data2;
recvdata[3]=data3;
MPI_Neighbor_alltoall(my_data , 1, mpi_weatherdata, data0, 1, mpi_weatherdata, cart_comm);
printf("data0: %i %i\n", recvdata[0]->speed, recvdata[0]->deg);
printf("data1: %i %i\n", recvdata[1]->speed, recvdata[1]->deg);
printf("data2: %i %i\n", recvdata[2]->speed, recvdata[2]->deg);
printf("data3: %i %i\n", recvdata[3]->speed, recvdata[3]->deg);
all i need is 'speed' and 'deg' from the weatherdata struct. my output looks something like:
Output
mpicc -o prog_weather weather.c tools_weather.c jsmn/libjsmn.a -lm
mpirun -np 80 prog_weather 5.0 47.0 14.0 55.0 1
dims: [9] [8]
Process rank: 40, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [5][0]
data0: 64 0
data1: 0 0
data2: 32660 1
data3: 0 29807328
Process rank: 41, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [5][1]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 42, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [5][2]
data0: 64 0
data1: 0 0
data2: 32606 1
data3: 0 32248544
Process rank: 43, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [5][3]
data0: 64 0
data1: 0 0
data2: 32741 1
data3: 0 8250080
Process rank: 44, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [5][4]
data0: 64 0
data1: 0 0
data2: 32643 1
data3: 0 14066400
Process rank: 45, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [5][5]
data0: 64 0
data1: 0 0
data2: 32646 1
data3: 0 31564512
Process rank: 46, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [5][6]
data0: 64 0
data1: 32583 28214128
data2: 0 25712112
data3: 0 0
Process rank: 47, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [5][7]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 48, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [6][0]
data0: 64 0
data1: 32712 1938112176
data2: 0 25453888
data3: 0 25409520
Process rank: 49, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [6][1]
data0: 64 0
data1: 32739 172736176
data2: 0 12830016
data3: 0 12785648
Process rank: 50, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [6][2]
data0: 64 0
data1: 32557 36845344
data2: 32557 1
data3: 0 33977056
Process rank: 51, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [6][3]
data0: 64 0
data1: 32722 -1205793104
data2: 0 37106912
data3: 0 37062544
Process rank: 52, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [6][4]
data0: 64 0
data1: 32745 1562607280
data2: 0 35345632
data3: 0 35301264
Process rank: 53, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [6][5]
data0: 64 0
data1: 32547 -746242384
data2: 0 29332800
data3: 0 29288432
Process rank: 54, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [6][6]
data0: 64 0
data1: 32763 1657695920
data2: 0 18199776
data3: 0 18155408
Process rank: 55, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [6][7]
data0: 64 0
data1: 32675 99397296
data2: 0 14841152
data3: 0 14796784
Process rank: 56, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [7][0]
data0: 64 0
data1: 32549 434941616
data2: 0 40248640
data3: 0 40204272
Process rank: 57, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [7][1]
data0: 64 0
data1: 32676 28069552
data2: 0 34342256
data3: 0 34297888
Process rank: 58, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [7][2]
data0: 64 0
data1: 32620 -1602105680
data2: 0 37168352
data3: 0 37123984
Process rank: 59, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [7][3]
data0: 64 0
data1: 32563 17697648
data2: 32563 1
data3: 0 14828256
Process rank: 60, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [7][4]
data0: 64 0
data1: 32643 19327824
data2: 32643 1
data3: 0 16458464
Process rank: 61, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [7][5]
data0: 64 0
data1: 32668 25882288
data2: 0 39998784
data3: 0 39954416
Process rank: 62, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [7][6]
data0: 64 0
data1: 32542 29244144
data2: 32543 1
data3: 0 26374880
Process rank: 63, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [7][7]
data0: 64 0
data1: 32621 478269104
data2: 0 28558656
data3: 0 28514288
Process rank: 64, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [8][0]
data0: 64 0
data1: 0 33
data2: 0 17102144
data3: 0 17057776
Process rank: 65, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [8][1]
data0: 64 0
data1: 0 33
data2: 0 20526400
data3: 0 20482032
Process rank: 66, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [8][2]
data0: 64 0
data1: 32618 22001504
data2: 0 19498480
data3: 0 0
Process rank: 67, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [8][3]
data0: 64 0
data1: 32633 27649920
data2: 0 25146896
data3: 0 0
Process rank: 68, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [8][4]
data0: 64 0
data1: 32624 33851264
data2: 0 31348208
data3: 0 0
Process rank: 69, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [8][5]
data0: 64 0
data1: 0 33
data2: 32756 -1639239568
data3: 0 0
Process rank: 70, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [8][6]
data0: 64 0
data1: 0 33
data2: 32558 1921785968
data3: 0 0
Process rank: 71, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [8][7]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 37767920
Process rank: 0, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [0][0]
lb: 0
extent: 28
offsets: 0
offsets: 4
offsets: 8
offsets: 12
offsets: 16
offsets: 20
offsets: 24
data0: 0 0
data1: 32553 13450944
data2: 32553 1
data3: 0 10580704
Process rank: 1, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [0][1]
data0: 0 0
data1: 0 0
data2: 32684 1
data3: 0 30442208
Process rank: 2, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [0][2]
data0: 0 0
data1: 0 0
data2: 32631 1
data3: 0 7869152
Process rank: 3, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [0][3]
data0: 0 0
data1: 0 0
data2: 32594 1
data3: 0 24773344
Process rank: 4, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [0][4]
data0: 0 0
data1: 0 0
data2: 32514 1
data3: 0 16143072
Process rank: 5, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [0][5]
data0: 0 0
data1: 0 0
data2: 32584 1
data3: 0 17621728
Process rank: 6, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [0][6]
data0: 0 0
data1: 0 0
data2: 32632 1
data3: 0 40121056
Process rank: 7, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [0][7]
data0: 0 0
data1: 0 0
data2: 32550 1
data3: 0 39789280
Process rank: 8, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [1][0]
data0: 64 0
data1: 0 0
data2: 32669 1
data3: 0 38523616
Process rank: 9, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [1][1]
data0: 64 0
data1: 0 0
data2: 32654 1
data3: 0 11518688
Process rank: 10, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [1][2]
data0: 64 0
data1: 0 0
data2: 32666 1
data3: 0 21218016
Process rank: 11, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [1][3]
data0: 64 0
data1: 0 0
data2: 32607 1
data3: 0 18789088
Process rank: 12, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [1][4]
data0: 64 0
data1: 0 0
data2: 32626 1
data3: 0 25527008
Process rank: 13, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [1][5]
data0: 64 0
data1: 0 0
data2: 32634 1
data3: 0 17969888
Process rank: 14, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [1][6]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 15, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [1][7]
data0: 64 0
data1: 0 0
data2: 32509 1
data3: 0 34927328
Process rank: 16, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [2][0]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 17, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [2][1]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 18, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [2][2]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 19, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [2][3]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 20, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [2][4]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 21, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [2][5]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 22, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [2][6]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 23, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [2][7]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 24, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [3][0]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 25, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [3][1]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 26, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [3][2]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 27, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [3][3]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 28, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [3][4]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 29, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [3][5]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 30, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [3][6]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 31, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [3][7]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 32, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [4][0]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 33, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [4][1]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 34, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [4][2]
data0: 64 0
data1: 0 0
data2: 32617 1
data3: 0 28934880
Process rank: 35, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [4][3]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 36, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [4][4]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 37, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [4][5]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 38, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [4][6]
data0: 64 0
data1: 0 0
data2: 0 0
data3: 0 0
Process rank: 39, Total Processes in Comm: 72, Process Name: HP-250-G5-Notebook-PC, Coordinates [4][7]
data0: 64 0
data1: 0 0
data2: 32678 1
data3: 0 39498464
MPI_Type_create_resized
call is useless since you are simply using whatever lower bound and extentMPI_Type_get_extent
gives you. This is not the problem though, since there is no padding in your particular case (extent is28
, which is equal to the offset of the last field +sizeof int
). The output as shown is hard to read and understand - please at least display the Cartesian coordinates of the ranks. – Hristo Iliev