computeFracMesh Subroutine

private subroutine computeFracMesh(mesh, vm, indices, frac, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_Mesh) :: mesh
type(ESMF_VM) :: vm
integer :: indices(:,:)
real(kind=ESMF_KIND_R8), pointer :: frac(:)
integer :: rc

Calls

proc~~computefracmesh~~CallsGraph proc~computefracmesh computeFracMesh interface~esmf_vmgather ESMF_VMGather proc~computefracmesh->interface~esmf_vmgather interface~esmf_vmgatherv ESMF_VMGatherV proc~computefracmesh->interface~esmf_vmgatherv interface~esmf_vmget ESMF_VMGet proc~computefracmesh->interface~esmf_vmget proc~esmf_vmgatherflogical2d ESMF_VMGatherFLogical2D interface~esmf_vmgather->proc~esmf_vmgatherflogical2d proc~esmf_vmgatheri4 ESMF_VMGatherI4 interface~esmf_vmgather->proc~esmf_vmgatheri4 proc~esmf_vmgatheri8 ESMF_VMGatherI8 interface~esmf_vmgather->proc~esmf_vmgatheri8 proc~esmf_vmgatherlogical ESMF_VMGatherLogical interface~esmf_vmgather->proc~esmf_vmgatherlogical proc~esmf_vmgatherr4 ESMF_VMGatherR4 interface~esmf_vmgather->proc~esmf_vmgatherr4 proc~esmf_vmgatherr8 ESMF_VMGatherR8 interface~esmf_vmgather->proc~esmf_vmgatherr8 proc~esmf_vmgathervi4 ESMF_VMGatherVI4 interface~esmf_vmgatherv->proc~esmf_vmgathervi4 proc~esmf_vmgathervi8 ESMF_VMGatherVI8 interface~esmf_vmgatherv->proc~esmf_vmgathervi8 proc~esmf_vmgathervr4 ESMF_VMGatherVR4 interface~esmf_vmgatherv->proc~esmf_vmgathervr4 proc~esmf_vmgathervr8 ESMF_VMGatherVR8 interface~esmf_vmgatherv->proc~esmf_vmgathervr8 proc~esmf_vmgetdefault ESMF_VMGetDefault interface~esmf_vmget->proc~esmf_vmgetdefault proc~esmf_vmgetpetspecific ESMF_VMGetPetSpecific interface~esmf_vmget->proc~esmf_vmgetpetspecific interface~c_esmc_vmgather c_ESMC_VMGather proc~esmf_vmgatherflogical2d->interface~c_esmc_vmgather interface~c_esmc_vmgathernb c_ESMC_VMGatherNB proc~esmf_vmgatherflogical2d->interface~c_esmc_vmgathernb proc~esmf_imerr ESMF_IMErr proc~esmf_vmgatherflogical2d->proc~esmf_imerr proc~esmf_logfounderror ESMF_LogFoundError proc~esmf_vmgatherflogical2d->proc~esmf_logfounderror proc~esmf_vmgetinit ESMF_VMGetInit proc~esmf_vmgatherflogical2d->proc~esmf_vmgetinit proc~esmf_vmgatheri4->interface~c_esmc_vmgather proc~esmf_vmgatheri4->interface~c_esmc_vmgathernb proc~esmf_vmgatheri4->proc~esmf_imerr proc~esmf_vmgatheri4->proc~esmf_logfounderror proc~esmf_vmgatheri4->proc~esmf_vmgetinit proc~esmf_vmgatheri8->interface~c_esmc_vmgather proc~esmf_vmgatheri8->interface~c_esmc_vmgathernb proc~esmf_vmgatheri8->proc~esmf_imerr proc~esmf_vmgatheri8->proc~esmf_logfounderror proc~esmf_vmgatheri8->proc~esmf_vmgetinit proc~esmf_vmgatherlogical->interface~c_esmc_vmgather proc~esmf_vmgatherlogical->interface~c_esmc_vmgathernb proc~esmf_vmgatherlogical->proc~esmf_imerr proc~esmf_vmgatherlogical->proc~esmf_logfounderror proc~esmf_vmgatherlogical->proc~esmf_vmgetinit proc~esmf_vmgatherr4->interface~c_esmc_vmgather proc~esmf_vmgatherr4->interface~c_esmc_vmgathernb proc~esmf_vmgatherr4->proc~esmf_imerr proc~esmf_vmgatherr4->proc~esmf_logfounderror proc~esmf_vmgatherr4->proc~esmf_vmgetinit proc~esmf_vmgatherr8->interface~c_esmc_vmgather proc~esmf_vmgatherr8->interface~c_esmc_vmgathernb proc~esmf_vmgatherr8->proc~esmf_imerr proc~esmf_vmgatherr8->proc~esmf_logfounderror proc~esmf_vmgatherr8->proc~esmf_vmgetinit interface~c_esmc_vmgatherv c_ESMC_VMGatherV proc~esmf_vmgathervi4->interface~c_esmc_vmgatherv proc~esmf_vmgathervi4->proc~esmf_imerr proc~esmf_vmgathervi4->proc~esmf_logfounderror proc~esmf_vmgathervi4->proc~esmf_vmgetinit proc~esmf_vmgathervi8->interface~c_esmc_vmgatherv proc~esmf_vmgathervi8->proc~esmf_imerr proc~esmf_vmgathervi8->proc~esmf_logfounderror proc~esmf_vmgathervi8->proc~esmf_vmgetinit proc~esmf_vmgathervr4->interface~c_esmc_vmgatherv proc~esmf_vmgathervr4->proc~esmf_imerr proc~esmf_vmgathervr4->proc~esmf_logfounderror proc~esmf_vmgathervr4->proc~esmf_vmgetinit proc~esmf_vmgathervr8->interface~c_esmc_vmgatherv proc~esmf_vmgathervr8->proc~esmf_imerr proc~esmf_vmgathervr8->proc~esmf_logfounderror proc~esmf_vmgathervr8->proc~esmf_vmgetinit proc~esmf_vmgetdefault->interface~esmf_vmget c_esmc_initget_esmf_comm c_esmc_initget_esmf_comm proc~esmf_vmgetdefault->c_esmc_initget_esmf_comm c_esmc_vmget c_esmc_vmget proc~esmf_vmgetdefault->c_esmc_vmget c_esmc_vmgetmpicommnull c_esmc_vmgetmpicommnull proc~esmf_vmgetdefault->c_esmc_vmgetmpicommnull c_esmc_vmgetssilocaldevlist c_esmc_vmgetssilocaldevlist proc~esmf_vmgetdefault->c_esmc_vmgetssilocaldevlist interface~esmf_interarraycreate ESMF_InterArrayCreate proc~esmf_vmgetdefault->interface~esmf_interarraycreate proc~esmf_vmgetdefault->proc~esmf_imerr proc~esmf_interarraydestroy ESMF_InterArrayDestroy proc~esmf_vmgetdefault->proc~esmf_interarraydestroy proc~esmf_vmgetdefault->proc~esmf_logfounderror proc~esmf_logseterror ESMF_LogSetError proc~esmf_vmgetdefault->proc~esmf_logseterror proc~esmf_vmgetdefault->proc~esmf_vmgetinit c_esmc_vmgetpetlocalinfo c_esmc_vmgetpetlocalinfo proc~esmf_vmgetpetspecific->c_esmc_vmgetpetlocalinfo proc~esmf_vmgetpetspecific->proc~esmf_imerr proc~esmf_vmgetpetspecific->proc~esmf_logfounderror proc~esmf_vmgetpetspecific->proc~esmf_vmgetinit

Source Code

subroutine computeFracMesh(mesh, vm, indices, frac, rc)
  type(ESMF_Mesh) :: mesh
  type(ESMF_VM) :: vm
  integer :: indices(:,:)
  real(ESMF_KIND_R8), pointer :: frac(:)
  integer :: rc

  integer (ESMF_KIND_I4) :: localCount(1)
  integer (ESMF_KIND_I4),pointer :: globalCount(:),globalDispl(:)
  integer (ESMF_KIND_I4),pointer :: buffer(:), buffer1(:)
  integer :: totalCount, maxIndex
  integer :: i, j, total
  integer :: petNo,petCnt
  integer :: count, saved

  call ESMF_VMGet(vm, localPet=PetNo, petCount=PetCnt, rc=rc)

  ! Allocate List of counts
  allocate(globalCount(petCnt))

  total = size(indices,2)
  ! find unique indices in the destination column: indices(2,:)
  count = 0
  saved = 0
  do i=1,total
    if (indices(2,i) /= saved) then
        count = count+1
        saved = indices(2,i)
    endif
  enddo
  allocate(buffer(count))
  saved = 0
  j=1
  do i=1,total
   if (indices(2,i) /= saved) then
     buffer(j)=indices(2,i)
     j=j+1
     saved = indices(2,i)
   endif
  enddo

  ! Get List of counts
  localCount(1)=count
  call ESMF_VMGather(vm,localCount,globalCount,count=1,rootPet=0,rc=rc)
  if (rc /=ESMF_SUCCESS) then
      return
  endif

! Calculate Displacements
  allocate(globalDispl(petCnt))
  if (petNo==0) then
     globalDispl(1)=0
     do i=2,petCnt
        globalDispl(i)=globalDispl(i-1)+globalCount(i-1)
     enddo
  else
    globalDispl=0
  endif


  ! Sum size
  if (petNo==0) then
    totalCount=0
    do i=1,petCnt
       totalCount=totalCount+globalCount(i)
    enddo
  else
    totalCount=1 ! Because I'm not sure what happens
                 ! if array is not allocated in VM
  endif


  ! Allocate final area list
  allocate(buffer1(totalCount))

  ! Gather all areas
  call ESMF_VMGatherV(vm,sendData=buffer, sendCount=localCount(1),&
         recvData=buffer1,recvCounts=globalCount,recvOffsets=globalDispl,&
         rootPet=0, rc=rc)
  if (rc /=ESMF_SUCCESS) then
      return
  endif

  if (PetNo==0) then
    maxIndex = maxval(buffer1)
    allocate(frac(maxIndex))
    frac = 0
    do i=1,totalCount
        frac(buffer1(i))=1
    enddo
  endif

  ! Get rid of helper variables
  deallocate(buffer, buffer1)
  deallocate(globalCount)
  deallocate(globalDispl)

end subroutine computeFracMesh