Skip to content

Commit 5896f46

Browse files
authored
Allocate dummy arrays to pass to mpp_gather calls (#1863)
1 parent 222f3c6 commit 5896f46

6 files changed

Lines changed: 87 additions & 10 deletions

File tree

diag_manager/diag_output.F90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ MODULE diag_output_mod
4848
use mpp_domains_mod, only: mpp_get_UG_io_domain
4949
use mpp_domains_mod, only: mpp_get_UG_domain_npes
5050
use mpp_domains_mod, only: mpp_get_UG_domain_pelist
51-
use mpp_mod, only: mpp_gather
5251
use mpp_mod, only: uppercase,lowercase
5352
use fms2_io_mod
5453

fms2_io/include/compressed_write.inc

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ subroutine compressed_write_1d(fileobj, variable_name, cdata, unlim_dim_level, &
137137
call error("unsupported variable type: "//trim(append_error_msg))
138138
end select
139139
else
140-
select type(cdata)
140+
select type(cdata)
141141
type is (integer(kind=i4_kind))
142142
allocate(buf_i4_kind(1))
143143
type is (integer(kind=i8_kind))
@@ -148,7 +148,7 @@ subroutine compressed_write_1d(fileobj, variable_name, cdata, unlim_dim_level, &
148148
allocate(buf_r8_kind(1))
149149
class default
150150
call error("unsupported variable type: "//trim(append_error_msg))
151-
end select
151+
end select
152152
endif
153153

154154
!Gather the data onto the I/O root and write it out.
@@ -253,6 +253,19 @@ subroutine compressed_write_2d(fileobj, variable_name, cdata, unlim_dim_level, &
253253
class default
254254
call error("unsupported variable type: "//trim(append_error_msg))
255255
end select
256+
else
257+
select type(cdata)
258+
type is (integer(kind=i4_kind))
259+
allocate(buf_i4_kind(1, 1))
260+
type is (integer(kind=i8_kind))
261+
allocate(buf_i8_kind(1, 1))
262+
type is (real(kind=r4_kind))
263+
allocate(buf_r4_kind(1, 1))
264+
type is (real(kind=r8_kind))
265+
allocate(buf_r8_kind(1, 1))
266+
class default
267+
call error("unsupported variable type: "//trim(append_error_msg))
268+
end select
256269
endif
257270

258271
c(:) = 1
@@ -376,7 +389,20 @@ subroutine compressed_write_3d(fileobj, variable_name, cdata, unlim_dim_level, &
376389
call allocate_array(buf_r8_kind, e)
377390
class default
378391
call error("unsupported variable type: "//trim(append_error_msg))
379-
end select
392+
end select
393+
else
394+
select type(cdata)
395+
type is (integer(kind=i4_kind))
396+
allocate(buf_i4_kind(1, 1, 1))
397+
type is (integer(kind=i8_kind))
398+
allocate(buf_i8_kind(1, 1, 1))
399+
type is (real(kind=r4_kind))
400+
allocate(buf_r4_kind(1, 1, 1))
401+
type is (real(kind=r8_kind))
402+
allocate(buf_r8_kind(1, 1, 1))
403+
class default
404+
call error("unsupported variable type: "//trim(append_error_msg))
405+
end select
380406
endif
381407

382408
c(:) = 1

fms2_io/include/domain_write.inc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,20 @@ subroutine domain_write_2d(fileobj, variable_name, vdata, unlim_dim_level, &
196196
call error("unsupported variable type: domain_write_2d_mpp_gather: file: " &
197197
& //trim(fileobj%path)//" variable:"//trim(variable_name))
198198
end select
199+
else
200+
select type(vdata)
201+
type is (integer(kind=i4_kind))
202+
allocate(global_buf_i4_kind(1, 1))
203+
type is (integer(kind=i8_kind))
204+
allocate(global_buf_i8_kind(1, 1))
205+
type is (real(kind=r4_kind))
206+
allocate(global_buf_r4_kind(1, 1))
207+
type is (real(kind=r8_kind))
208+
allocate(global_buf_r8_kind(1, 1))
209+
class default
210+
call error("unsupported variable type: domain_write_2d_mpp_gather: file: " &
211+
& //trim(fileobj%path)//" variable:"//trim(variable_name))
212+
end select
199213
endif
200214

201215
! Get the starting and indices of the compute domain relative to vdata (note that vdata start indices at 1 #Fortran)
@@ -374,6 +388,20 @@ subroutine domain_write_3d(fileobj, variable_name, vdata, unlim_dim_level, &
374388
call error("unsupported variable type: domain_write_3d_mpp_gather: file: " &
375389
& //trim(fileobj%path)//" variable:"//trim(variable_name))
376390
end select
391+
else
392+
select type(vdata)
393+
type is (integer(kind=i4_kind))
394+
allocate(global_buf_i4_kind(1, 1, 1))
395+
type is (integer(kind=i8_kind))
396+
allocate(global_buf_i8_kind(1, 1, 1))
397+
type is (real(kind=r4_kind))
398+
allocate(global_buf_r4_kind(1, 1, 1))
399+
type is (real(kind=r8_kind))
400+
allocate(global_buf_r8_kind(1, 1, 1))
401+
class default
402+
call error("unsupported variable type: domain_write_3d_mpp_gather: file: " &
403+
& //trim(fileobj%path)//" variable:"//trim(variable_name))
404+
end select
377405
endif
378406

379407
! Get the starting and indices of the compute domain relative to vdata(note that vdata start indices at 1 #Fortran)

fms2_io/include/gather_data_bc.inc

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ subroutine gather_data_bc_2d(fileobj, vdata, bc_info)
8181
i1=1; i2=1; j1=1; j2=1
8282
else
8383
!! In this case there is data in fileobj's root, so there is no need for the dummy data
84-
if(fileobj%is_root) allocate(global_buf_r4_kind(i_glob, j_glob))
84+
if(fileobj%is_root) then
85+
allocate(global_buf_r4_kind(i_glob, j_glob))
86+
else
87+
allocate(global_buf_r4_kind(1, 1))
88+
endif
8589
allocate(local_buf_r4_kind(size(vdata,1), size(vdata,2)))
8690
local_buf_r4_kind = vdata
8791
endif
@@ -112,7 +116,11 @@ subroutine gather_data_bc_2d(fileobj, vdata, bc_info)
112116
i1=1; i2=1; j1=1; j2=1
113117
else
114118
!! In this case there is data in fileobj's root, so there is no need for the dummy data
115-
if(fileobj%is_root) allocate(global_buf_r8_kind(i_glob, j_glob))
119+
if(fileobj%is_root) then
120+
allocate(global_buf_r8_kind(i_glob, j_glob))
121+
else
122+
allocate(global_buf_r8_kind(1, 1))
123+
endif
116124
allocate(local_buf_r8_kind(size(vdata,1), size(vdata,2)))
117125
local_buf_r8_kind = vdata
118126
endif
@@ -203,7 +211,11 @@ subroutine gather_data_bc_3d(fileobj, vdata, bc_info)
203211
i1=1; i2=1; j1=1; j2=1
204212
else
205213
!! In this case there is data in fileobj's root, so there is no need for the dummy data
206-
if(fileobj%is_root) allocate(global_buf_r4_kind(i_glob, j_glob, k_glob))
214+
if(fileobj%is_root) then
215+
allocate(global_buf_r4_kind(i_glob, j_glob, k_glob))
216+
else
217+
allocate(global_buf_r4_kind(1, 1, 1))
218+
endif
207219
allocate(local_buf_r4_kind(size(vdata,1), size(vdata,2), size(vdata,3)))
208220
local_buf_r4_kind = vdata
209221
endif
@@ -233,7 +245,11 @@ subroutine gather_data_bc_3d(fileobj, vdata, bc_info)
233245
i1=1; i2=1; j1=1; j2=1
234246
else
235247
!! In this case there is data in fileobj's root, so there is no need for the dummy data
236-
if(fileobj%is_root) allocate(global_buf_r8_kind(i_glob, j_glob, k_glob))
248+
if(fileobj%is_root) then
249+
allocate(global_buf_r8_kind(i_glob, j_glob, k_glob))
250+
else
251+
allocate(global_buf_r8_kind(1, 1, 1))
252+
endif
237253
allocate(local_buf_r8_kind(size(vdata,1), size(vdata,2), size(vdata,3)))
238254
local_buf_r8_kind = vdata
239255
endif

mpp/include/mpp_gather.fh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,11 @@ subroutine MPP_GATHER_PELIST_GEN_3D_(is, ie, js, je, nk, pelist, array_seg, gath
212212
if (present(jshift)) joff=jshift
213213

214214
! gather indices into global index on root_pe
215-
if (is_root_pe) allocate(gind(4*size(pelist)))
215+
if (is_root_pe) then
216+
allocate(gind(4*size(pelist)))
217+
else
218+
allocate(gind(1))
219+
endif
216220
call mpp_gather((/is, ie, js, je/), gind, pelist)
217221

218222
! Compute recv counts and allocate 1d recv buffer (rbuf)

mpp/include/mpp_write_unlimited_axis.fh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@
4343

4444
nelems = sum(nelems_io(:))
4545

46-
if(mpp_file(unit)%write_on_this_pe) allocate(rbuff(nelems))
46+
if(mpp_file(unit)%write_on_this_pe) then
47+
allocate(rbuff(nelems))
48+
else
49+
allocate(rbuff(1))
50+
endif
4751

4852
! Note that the gatherV implied here is asymmetric; only root needs to know the vector of recv size
4953
call mpp_gather(data,size(data),rbuff,nelems_io(:),pelist)

0 commit comments

Comments
 (0)