parallel processing - Using MPI_TYPE_VECTOR instead of MPI_GATHER -
suppose k processes compute elements of matrix a, dimension (n,m), n number of rows , m number of columns. trying use mpi_gather gather these 2 matrices matrix b @ root process, dimension of b (n,km). more specific, wrote example fortran code below. here, passing on columns of matrix a (not entire matrix) matrix b wouldn't work. when run executable using mpirun -n 2 a.out, error:
malloc: *** error object 0x7ffa89413fb8: incorrect checksum freed object - object modified after being freed.
1) why error message?
2) can please explain conceptually, why have use mpi_type_vector?
3) how should correct mpi_gather part of code? can pass on entire matrix a?
program test implicit none include "mpif.h" integer, parameter :: n=100, m=100 integer, allocatable, dimension(:,:) :: integer, dimension(n,m) :: b integer :: ind_a, ind_c integer :: num_proc, proc_id, ierror, master_id=0 integer :: c integer, dimension(m) :: cvec call mpi_init(ierror) call mpi_comm_rank(mpi_comm_world, proc_id, ierror) call mpi_comm_size(mpi_comm_world, num_proc, ierror) allocate(a(n,m/num_proc)) ind_c=1,m cvec(ind_c)=ind_c end ! fill in matrix ind_a=1,n ind_c=1,m/num_proc c=cvec(ind_c+proc_id*m/num_proc) a(ind_a,ind_c)=c*ind_a end end ! gather elements @ root process ind_a=1,n call mpi_gather(a(ind_a,:),m/num_proc,mpi_integer,b(ind_a,proc_id*m/num_proc+1:(proc_id+1)*m/num_proc),m/num_proc,mpi_integer,master_id,mpi_comm_world,ierror) end call mpi_finalize(ierror) end program
there 2 types of gather operation can performed in 2 dimensional array. 1. gathering elements dimension-2 of process , collecting in dimension-2 of 1 process; , 2. gathering elements dimension-2 of process , collecting in dimension-1 of 1 process.
said in example; n=dimension-1 , m=dimension-2, , know fortran column major. hence, dimension-1 contiguous in memory in fortran.
in gather statement trying gather dimension-2 of array-a processes, , collect dimension-2 of array-b in master_id proc(type-1). since, dimension-2 non-contiguous in memory, causes segmentation fault.
a single mpi_gather call shown below required operation, without looping-tricks shown above:
call mpi_gather(a, n*(m/num_proc), mpi_integer, & b, n*(m/num_proc), mpi_integer, master_id, & mpi_comm_world, ierror)
but, if attempting gather elements dimension-2 of array-a process dimension-1 of array-b in master_id proc, when need make use of mpi_type_vector, create new type non-contiguous elements. let, me know if intention.
because, current code logic doesn't need make use of mpi_type_vector.
Comments
Post a Comment