Edit PIO_initdecomp examples here.

  subroutine GetIODOF(ndims, gdims, iorank, iodof, start, count, decompz)
    integer, intent(in) :: ndims
    integer, intent(in) :: gdims(ndims)
    integer, intent(in) :: iorank
    logical, intent(in), optional :: decompz
    integer(kind=PIO_Offset), intent(out) :: start(ndims), count(ndims)
    integer, intent(out), allocatable :: iodof(:)
    integer :: nzrank, nxrank, nx, k, i, j, l_ndims, icnt
    start=1
    count=0
    if(iorank>=0) then
       if(present(decompz)) then
          if(decompz) then
             l_ndims=ndims
          else
             l_ndims=ndims-1
             count(ndims)=gdims(ndims)
             start(ndims)=1
          endif
       else
          l_ndims=ndims
       end if
       nx=num_io_procs
       count(l_ndims)=max(1,gdims(l_ndims)/num_io_procs)
       nx=max(1,num_io_procs/gdims(l_ndims))
       nzrank=iorank/nx
       k=num_io_procs-gdims(l_ndims)*nx
       if(iorank>num_io_procs-k-1.and.k>0) then
          nzrank=gdims(l_ndims)-1
       end if
       start(l_ndims)=nzrank*count(l_ndims)+1
       if(gdims(l_ndims)>num_io_procs) then
          k=gdims(l_ndims)-num_io_procs*count(l_ndims)
          if(k>iorank) then
             count(l_ndims)=count(l_ndims)+1
          end if
          if(k>=iorank) then
             start(l_ndims)=start(l_ndims)+iorank
          else
             start(l_ndims)=start(l_ndims)+k
          end if
       end if
       if(k>0 .and.nzrank==gdims(l_ndims)-1 ) then
          nx=nx+k
       end if
       nxrank=iorank
       do i=l_ndims-1,1,-1
          nxrank=mod(nxrank,nx)
          count(i)=gdims(i)/nx
          k=gdims(i)-count(i)*nx
          if(nxrank<k) then
             count(i)=count(i)+1
             start(i)=count(i)*nxrank+1
          else
             start(i)=count(i)*nxrank+k+1
          end if
          nx=max(1,num_io_procs/gdims(i))
       end do
h3.        print *,__FILE__,__LINE__,start(1:ndims),count(1:ndims)
       icnt=0
       if(ndims.eq.1) then
          allocate(iodof(count(1)))
          do i=start(1),start(1)+count(1)-1
             iodof(i)=i
          end do
       else if(ndims.eq.2) then
          allocate(iodof(count(1)*count(2)))
          do j=start(2),start(2)+count(2)-1
             do i=start(1),start(1)+count(1)-1
                icnt=icnt+1
                iodof(icnt)=i+gdims(1)*(j-1)
             end do
          end do
       else
          allocate(iodof(count(1)[count(2)]count(3)))
          do k=start(3),start(3)+count(3)-1
             do j=start(2),start(2)+count(2)-1
                do i=start(1),start(1)+count(1)-1
                   icnt=icnt+1
                   iodof(icnt)=i+gdims(1)[(j-1)+gdims(1)]gdims(2)*(k-1)
                   if(iodof(icnt).eq.577.or.iodof(icnt).eq.221185) then
                      print *,__FILE__,__LINE__,iodof(icnt),icnt,i,j,k
                   end if
                end do
             end do
          end do
       end if
h3.        print *,__FILE__,__LINE__,minval(iodof),maxval(iodof),icnt,start(1:ndims),count(1:ndims)
    else	
       allocate(iodof(1))
       iodof=-1
    end if
  end subroutine GetIODOF
  • No labels