Hello,<div><br></div><div>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. </div>
<div><br></div><div><div>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){</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">  </span>int i,j, index;</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>int tmp_target;</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>int *flag;</div><div><span class="Apple-tab-span" style="white-space:pre">   </span>int *source_disp;</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>int *target_disp;</div><div><span class="Apple-tab-span" style="white-space:pre">    </span>MPI_Datatype source_type, target_type;</div><div><span class="Apple-tab-span" style="white-space:pre">       </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span></div><div><span class="Apple-tab-span" style="white-space:pre">     </span>MPI_Alloc_mem( size*sizeof(int), MPI_INFO_NULL, &source_disp);</div><div><span class="Apple-tab-span" style="white-space:pre">   </span>MPI_Alloc_mem( size*sizeof(int), MPI_INFO_NULL, &target_disp);</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>MPI_Alloc_mem( size*sizeof(int), MPI_INFO_NULL, &flag );</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>memset(flag, 0, size*sizeof(int));</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">     </span>for(i=0;i<size;i++){</div><div><span class="Apple-tab-span" style="white-space:pre">              </span>if(flag[i]==0){</div><div><span class="Apple-tab-span" style="white-space:pre">                      </span>tmp_target = target[i];</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span></div><div><span class="Apple-tab-span" style="white-space:pre">                     </span>index = 0;</div><div><span class="Apple-tab-span" style="white-space:pre">                   </span>for(j=i; j<size; j++){</div>
<div><span class="Apple-tab-span" style="white-space:pre">                              </span>if(flag[j]==0 && tmp_target == target[j] ){</div><div><span class="Apple-tab-span" style="white-space:pre">                                  </span>source_disp[index] = sources_disp[j];</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                      </span>target_disp[index] = targets_disp[j];</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>//printf("src, target disp %d  %d\n", j, disp[j]);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                      </span>index++;</div><div><span class="Apple-tab-span" style="white-space:pre">                                     </span>flag[j] = 1;</div><div><span class="Apple-tab-span" style="white-space:pre">                         </span> }</div>
<div><span class="Apple-tab-span" style="white-space:pre">                      </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                   </span>MPI_Type_indexed(index, blength , source_disp, dtype, &source_type);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                      </span>MPI_Type_commit(&source_type);</div><div><span class="Apple-tab-span" style="white-space:pre">                   </span>MPI_Type_indexed(index, blength , target_disp, dtype, &target_type);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                      </span>MPI_Type_commit(&target_type);</div><div><span class="Apple-tab-span" style="white-space:pre">                   </span></div><div><span class="Apple-tab-span" style="white-space:pre">                     </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">                      </span>MPI_Accumulate( data, 1, source_type, tmp_target, 0, 1, target_type , op, win);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                     </span>MPI_Type_free(&source_type);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                      </span>MPI_Type_free(&target_type);</div><div><span class="Apple-tab-span" style="white-space:pre">             </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">    </span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>MPI_Free_mem(source_disp);</div><div><span class="Apple-tab-span" style="white-space:pre">   </span>MPI_Free_mem(target_disp);</div><div><span class="Apple-tab-span" style="white-space:pre">   </span>MPI_Free_mem(flag);</div>
<div><br></div><div>}</div><div><br></div><div>void main(){</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>int i;</div><div><span class="Apple-tab-span" style="white-space:pre">       </span>while(i<N){</div>
<div><span class="Apple-tab-span" style="white-space:pre">                      </span> MPI_Win_fence(MPI_MODE_NOPRECEDE, queue2_win);</div><div><span class="Apple-tab-span" style="white-space:pre">                      </span> </div><div><span class="Apple-tab-span" style="white-space:pre">                    </span> data_transfer();</div>
<div><span class="Apple-tab-span" style="white-space:pre">                      </span> </div><div><span class="Apple-tab-span" style="white-space:pre">                    </span> MPI_Win_fence(MPI_MODE_NOSUCCEED, queue2_win);</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>}</div>
<div>}</div></div><div><br></div><div>Thanks</div><div>Ziaul</div>