[mpich-discuss] MPI One-Sided Communication, and indexed datatype

Ziaul Haque Olive mzh.olive at gmail.com
Thu May 31 18:23:11 CDT 2012


Hello,

I am not sure, if my code is correct according to MPICH2(v1.4.1p1.). the
code is given as follows, I am doing MPI one-sided communication inside a
function - data_transfer. this function is being called inside a fence
epoch. inside data_transfer, I am allocating memory for non-contiguous
data, creating derived data type, using this datatype in MPI_Accumulate,
and after calling MPI_Accumulate, freeing the indexed data type and also
freeing the memory containing indices for indexed data type. is it okay
that I am freeing memory before the closing fence.

void data_transfer(void *data, int *sources_disp, int *targets_disp, int
*target, int size, int *blength, int func, MPI_Op op, MPI_Win win,
MPI_Datatype dtype){

int i,j, index;
int tmp_target;
int *flag;
int *source_disp;
int *target_disp;
MPI_Datatype source_type, target_type;
 MPI_Alloc_mem( size*sizeof(int), MPI_INFO_NULL, &source_disp);
MPI_Alloc_mem( size*sizeof(int), MPI_INFO_NULL, &target_disp);
MPI_Alloc_mem( size*sizeof(int), MPI_INFO_NULL, &flag );

memset(flag, 0, size*sizeof(int));

for(i=0;i<size;i++){
if(flag[i]==0){
tmp_target = target[i];
 index = 0;
for(j=i; j<size; j++){
if(flag[j]==0 && tmp_target == target[j] ){
source_disp[index] = sources_disp[j];
target_disp[index] = targets_disp[j];
//printf("src, target disp %d  %d\n", j, disp[j]);
index++;
flag[j] = 1;
 }
}

MPI_Type_indexed(index, blength , source_disp, dtype, &source_type);
MPI_Type_commit(&source_type);
MPI_Type_indexed(index, blength , target_disp, dtype, &target_type);
MPI_Type_commit(&target_type);
 MPI_Accumulate( data, 1, source_type, tmp_target, 0, 1, target_type , op,
win);

MPI_Type_free(&source_type);
MPI_Type_free(&target_type);
}
}
MPI_Free_mem(source_disp);
MPI_Free_mem(target_disp);
MPI_Free_mem(flag);

}

void main(){
int i;
while(i<N){
 MPI_Win_fence(MPI_MODE_NOPRECEDE, queue2_win);

 data_transfer();

 MPI_Win_fence(MPI_MODE_NOSUCCEED, queue2_win);
}
}

Thanks
Ziaul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20120531/8658cdbe/attachment.html>


More information about the mpich-discuss mailing list