Using Gatherv for 2d Arrays in Fortran

烈酒焚心 提交于 2019-12-06 10:09:40

there are two issues in your program :

replace

extent =  2*9 *  int_size

with

extent =  2 *  int_size

and replace

displs(i) = (i-1) * 2 * 9 

with

displs(i) = (i-1)

and you should be fine

 ##########################
[ 3]       1;        11;        21;        31;        41;        51;        61;        71;    
[ 3]       2;        12;        22;        32;        42;        52;        62;        72;    
[ 3]       3;        13;        23;        33;        43;        53;        63;        73;    
[ 3]       4;        14;        24;        34;        44;        54;        64;        74;    
[ 3]       5;        15;        25;        35;        45;        55;        65;        75;    
[ 3]       6;        16;        26;        36;        46;        56;        66;        76;    
[ 3]       7;        17;        27;        37;        47;        57;        67;        77;    
[ 3]       8;        18;        28;        38;        48;        58;        68;        78;    
[ 3]       9;        19;        29;        39;        49;        59;        69;        79;    

generally speaking, i do not think MPI_Type_create_subarray is a good fit for scatter/gather, in this case, you can simply use MPI_Type_vector

call MPI_Type_vector(9, 2, 8, MPI_INTEGER4, newtype, ierr)

(note, you still need to MPI_Type_create_resized)

last but not least, you do not really need MPI_Gatherv here,

call MPI_Gather(local, 2*9, MPI_INTEGER4, &
    global, 1, resizedtype, &
    root, MPI_COMM_WORLD, ierr)

is good enough here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!