首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >避免在带有标头的数据文件中重复使用MPI_File_set_view

避免在带有标头的数据文件中重复使用MPI_File_set_view
EN

Stack Overflow用户
提问于 2018-04-20 00:26:09
回答 1查看 152关注 0票数 0

我正在从https://github.com/LadaF/PoisFFT/blob/master/src/testmpi.f90 (最后是save_vtk())更新一个简单的MPI-IO子例程,这多少有点像MPI I/O, mix of single- and multiple-process output的精神。我的目的是在一个更重要的程序中使用这个过程。

我看到了这段代码,它会产生正确的输出(删除错误检查):

这只完成了一次,并且对性能影响不大:

代码语言:javascript
复制
if (master) then
  header =  ... !the header from the link above in a long string
end if
call MPI_Bcast(header_len, storage_size(header_len)/8, &
      MPI_BYTE, 0, glob_comm, ie)

call MPI_Type_create_subarray(3, int(ng), int(nxyz), int(off), &
   MPI_ORDER_FORTRAN, MPI_RP, filetype, ie)

call MPI_type_commit(filetype, ie)

这样做了很多次:

代码语言:javascript
复制
call MPI_File_open(glob_comm,"out.vtk", &
       IOR(IOR(MPI_MODE_CREATE, MPI_MODE_WRONLY), &
       MPI_MODE_EXCL), MPI_INFO_NULL, fh, ie)

if (ie/=0) then                  !should not happen in serious computations
  call MPI_Barrier(glob_comm, ie)

  if (master) call MPI_File_delete("out.vtk",MPI_INFO_NULL, ie)

  call MPI_Barrier(glob_comm, ie)

  call MPI_File_open(glob_comm,"out.vtk", &
         IOR(MPI_MODE_CREATE, MPI_MODE_WRONLY),&
         MPI_INFO_NULL, fh, ie)
end if

call MPI_File_set_view(fh, 0_MPI_OFFSET_KIND, &
       MPI_CHARACTER, MPI_CHARACTER, "native", &
       MPI_INFO_NULL, ie)

if (master) then
   call MPI_File_write(fh, header, header_len, &
         MPI_CHARACTER, MPI_STATUS_IGNORE, ie)
end if

call MPI_Barrier(glob_comm, ie)
call MPI_File_set_view(fh, header_len, MPI_RP, &
       filetype, "native", MPI_INFO_NULL, ie)

call MPI_File_write_all(fh, buffer, nx*ny*nz, MPI_RP, &
       MPI_STATUS_IGNORE, ie)

call MPI_File_close(fh, ie)

代码首先测试文件是否已经存在,如果存在,则删除该文件并重新打开。完整的可测试代码位于新的git分支(https://github.com/LadaF/PoisFFT/blob/new_mpi_io/src/testmpi.f90)中。

我想去掉重复的MPI_File_set_view(),或者至少去掉其间的MPI_Barrier(),以便直接为数组的头和块设置根进程的视图,然后让根进程将头和数组块都写入视图中。

这有可能吗?

EN

回答 1

Stack Overflow用户

发布于 2018-04-20 00:42:29

我会让根进程只使用带有'replace‘的fortran streamIO来去掉MPI_File_delete以及多个视图和屏障调用:

代码语言:javascript
复制
if (master) then
  open(file="out.vtk", access='stream', status='replace', newunit=out)
  write(out) header
  close(out)
endif

call MPI_Barrier(...)

call MPI_File_open(...)

call MPI_File_setview(...)

call MPI_File_write_all(...)

call MPI_File_close(...)

仍然有一个障碍,但我看不到绕过它的方法。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49925937

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档