Skip to content

Commit 4fab3c8

Browse files
authored
Merge branch 'iulian787/move_semoab' (PR E3SM-Project#6369)
semoab_mod.F90 file is moved from components/eam/src/dynamics/se folder to components/homme/src/share folder. It belongs naturally there, as it involves just grid routines from homme base code also, it should prepare for SCREAM-moab connection later on fix also some complaints about non-allocated arrays when there are no cells on some dynamic tasks (when number of tasks is larger than number of spectral cells in homme) [BFB]
2 parents 58f1c6e + 592df47 commit 4fab3c8

File tree

1 file changed

+42
-39
lines changed

1 file changed

+42
-39
lines changed

components/eam/src/dynamics/se/semoab_mod.F90 renamed to components/homme/src/share/semoab_mod.F90

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ module semoab_mod
1212

1313
use dimensions_mod, only: nelem, ne, np, nelemd, nlev
1414
use element_mod, only : element_t
15-
use parallel_mod, only : parallel_t
15+
use parallel_mod, only : parallel_t, abortmp
1616

1717
use m_MergeSorts, only: IndexSet, IndexSort
1818

19-
use cam_grid_support, only: iMap
20-
use cam_abortutils, only : endrun
2119
use edgetype_mod, only: edgedescriptor_t
2220
use gridgraph_mod, only: gridvertex_t
2321

@@ -209,8 +207,10 @@ subroutine create_moab_meshes(par, elem)
209207
if ( nelemd > 0 ) then
210208
allocate(moab_vert_coords(3*nverts) )
211209
allocate(vdone(nverts))
212-
vdone = 0;
210+
else
211+
allocate(vdone(1)) ! will be passed to iMOAB_ResolveSharedEnts, and compilers are complaining about non-allocated arrays
213212
endif
213+
vdone = 0;
214214
if ( nelemd > 0 ) currentval = gdofv( indx(1)) ! start over to identify coordinates of the vertices
215215

216216
do ix=1,moab_dim_cquads
@@ -251,7 +251,7 @@ subroutine create_moab_meshes(par, elem)
251251
if ( nelemd > 0 ) then
252252
ierr = iMOAB_CreateVertices(MHFID, dimcoord, dimen, moab_vert_coords)
253253
if (ierr > 0 ) &
254-
call endrun('Error: fail to create MOAB vertices ')
254+
call abortmp('Error: fail to create MOAB vertices ')
255255
endif
256256
!!num_el = nelemd2
257257
mbtype = 3 ! quadrilateral
@@ -261,7 +261,7 @@ subroutine create_moab_meshes(par, elem)
261261
if ( nelemd > 0 ) then
262262
ierr = iMOAB_CreateElements( MHFID, nelemd2, mbtype, nve, moabconn, block_ID );
263263
if (ierr > 0 ) &
264-
call endrun('Error: fail to create MOAB elements')
264+
call abortmp('Error: fail to create MOAB elements')
265265
endif
266266
! nverts: num vertices; vdone will store now the markers used in global resolve
267267
! for this particular problem, markers are the global dofs at corner nodes
@@ -272,18 +272,19 @@ subroutine create_moab_meshes(par, elem)
272272
numco = 1
273273
ierr = iMOAB_DefineTagStorage(MHFID, tagname, tagtype, numco, tagindex )
274274
if (ierr > 0 ) &
275-
call endrun('Error: fail to retrieve global id tag')
275+
call abortmp('Error: fail to retrieve global id tag')
276276
! now set the values
277277
ent_type = 0 ! vertex type
278278
if ( nverts > 0 ) then
279279
ierr = iMOAB_SetIntTagStorage ( MHFID, tagname, nverts , ent_type, vdone)
280280
if (ierr > 0 ) &
281-
call endrun('Error: fail to set marker id tag for vertices')
281+
call abortmp('Error: fail to set marker id tag for vertices')
282282
endif
283283

284+
! we need to call this even when no mesh locally, it involves a collective
284285
ierr = iMOAB_ResolveSharedEntities( MHFID, nverts, vdone );
285286
if (ierr > 0 ) &
286-
call endrun('Error: fail to resolve shared entities')
287+
call abortmp('Error: fail to resolve shared entities')
287288

288289
if ( nelemd > 0) then
289290
vdone = -1 ! reuse vdone for the new tag, GLOBAL_ID (actual tag that we want to store global dof )
@@ -294,7 +295,7 @@ subroutine create_moab_meshes(par, elem)
294295
newtagg='GLOBAL_ID'//C_NULL_CHAR
295296
ierr = iMOAB_DefineTagStorage(MHFID, newtagg, tagtype, numco, tagindex )
296297
if (ierr > 0 ) &
297-
call endrun('Error: fail to create new GDOF tag')
298+
call abortmp('Error: fail to create new GDOF tag')
298299
do ie=1,nelemd
299300
do ii=1,elem(ie)%idxp%NumUniquePts
300301
i=elem(ie)%idxp%ia(ii)
@@ -310,19 +311,19 @@ subroutine create_moab_meshes(par, elem)
310311
if ( nverts > 0 ) then
311312
ierr = iMOAB_SetIntTagStorage ( MHFID, newtagg, nverts , ent_type, vdone)
312313
if (ierr > 0 ) &
313-
call endrun('Error: fail to set global dof tag for vertices')
314+
call abortmp('Error: fail to set global dof tag for vertices')
314315
endif
315316

316317
ierr = iMOAB_ReduceTagsMax ( MHFID, tagindex, ent_type)
317318
if (ierr > 0 ) &
318-
call endrun('Error: fail to reduce max tag')
319+
call abortmp('Error: fail to reduce max tag')
319320

320321
! set global id tag for elements
321322
ent_type = 1 ! now set the global id tag on elements
322323
if ( nelemd2 > 0 ) then
323324
ierr = iMOAB_SetIntTagStorage ( MHFID, newtagg, nelemd2 , ent_type, elemids)
324325
if (ierr > 0 ) &
325-
call endrun('Error: fail to set global id tag for elements')
326+
call abortmp('Error: fail to set global id tag for elements')
326327
endif
327328

328329
! now, after reduction, we can get the actual global ids for each vertex in the fine mesh
@@ -333,18 +334,18 @@ subroutine create_moab_meshes(par, elem)
333334
allocate(vgids(nverts))
334335
ierr = iMOAB_GetIntTagStorage ( MHFID, newtagg, nverts , ent_type, vgids)
335336
if (ierr > 0 ) &
336-
call endrun('Error: fail to retrieve GLOBAL ID on each task')
337+
call abortmp('Error: fail to retrieve GLOBAL ID on each task')
337338
endif
338339
ierr = iMOAB_UpdateMeshInfo(MHFID)
339340
if (ierr > 0 ) &
340-
call endrun('Error: fail to update mesh info')
341+
call abortmp('Error: fail to update mesh info')
341342
#ifdef MOABDEBUG
342343
! write out the mesh file to disk, in parallel
343344
outfile = 'wholeFineATM.h5m'//C_NULL_CHAR
344345
wopts = 'PARALLEL=WRITE_PART'//C_NULL_CHAR
345346
ierr = iMOAB_WriteMesh(MHFID, outfile, wopts)
346347
if (ierr > 0 ) &
347-
call endrun('Error: fail to write the mesh file')
348+
call abortmp('Error: fail to write the mesh file')
348349
#endif
349350

350351

@@ -422,7 +423,7 @@ subroutine create_moab_meshes(par, elem)
422423
if ( nverts_c > 0 ) then
423424
ierr = iMOAB_CreateVertices(MHID, dimcoord, dimen, moab_vert_coords)
424425
if (ierr > 0 ) &
425-
call endrun('Error: fail to create MOAB vertices ')
426+
call abortmp('Error: fail to create MOAB vertices ')
426427
endif
427428
! num_el = nelemd
428429
mbtype = 3 ! quadrilateral
@@ -432,7 +433,7 @@ subroutine create_moab_meshes(par, elem)
432433
if ( nelemd > 0 ) then
433434
ierr = iMOAB_CreateElements( MHID, nelemd, mbtype, nve, moabconn_c, block_ID );
434435
if (ierr > 0 ) &
435-
call endrun('Error: fail to create MOAB elements')
436+
call abortmp('Error: fail to create MOAB elements')
436437
endif
437438
! idx: num vertices; vdone will store now the markers used in global resolve
438439
! for this particular problem, markers are the global dofs at corner nodes
@@ -443,36 +444,36 @@ subroutine create_moab_meshes(par, elem)
443444
numco = 1
444445
ierr = iMOAB_DefineTagStorage(MHID, tagname, tagtype, numco, tagindex )
445446
if (ierr > 0 ) &
446-
call endrun('Error: fail to retrieve GDOFV id tag')
447+
call abortmp('Error: fail to retrieve GDOFV id tag')
447448
ierr = iMOAB_DefineTagStorage(MHID, newtagg, tagtype, numco, tagindex )
448449
if (ierr > 0 ) &
449-
call endrun('Error: fail to retrieve GLOBAL_ID tag on coarse mesh')
450+
call abortmp('Error: fail to retrieve GLOBAL_ID tag on coarse mesh')
450451
! now set the values
451452
ent_type = 0 ! vertex type
452453
if ( nverts_c > 0 ) then
453454
ierr = iMOAB_SetIntTagStorage ( MHID, tagname, nverts_c , ent_type, vdone_c)
454455
if (ierr > 0 ) &
455-
call endrun('Error: fail to set GDOFV tag for vertices')
456+
call abortmp('Error: fail to set GDOFV tag for vertices')
456457
endif
457458
! set global id tag for coarse elements, too; they will start at nets=1, end at nete=nelemd
458459
ent_type = 1 ! now set the global id tag on elements
459460
if ( nelemd > 0 ) then
460461
ierr = iMOAB_SetIntTagStorage ( MHID, newtagg, nelemd , ent_type, elemids)
461462
if (ierr > 0 ) &
462-
call endrun('Error: fail to set global id tag for vertices')
463+
call abortmp('Error: fail to set global id tag for vertices')
463464
endif
464465

465466
ierr = iMOAB_ResolveSharedEntities( MHID, idx, vdone_c );
466467
if (ierr > 0 ) &
467-
call endrun('Error: fail to resolve shared entities')
468+
call abortmp('Error: fail to resolve shared entities')
468469

469470
! global dofs are the GLL points are set for each element
470471
tagname='GLOBAL_DOFS'//C_NULL_CHAR
471472
tagtype = 0 ! dense, integer
472473
numco = np*np ! usually, it is 16; each element will have the dofs in order
473474
ierr = iMOAB_DefineTagStorage(MHID, tagname, tagtype, numco, tagindex )
474475
if (ierr > 0 ) &
475-
call endrun('Error: fail to create global DOFS tag')
476+
call abortmp('Error: fail to create global DOFS tag')
476477
! now set the values
477478
! set global dofs tag for coarse elements, too; they will start at nets=1, end at nete=nelemd
478479
ent_type = 1 ! now set the global id tag on elements
@@ -499,27 +500,27 @@ subroutine create_moab_meshes(par, elem)
499500
if ( nelemd > 0 ) then
500501
ierr = iMOAB_SetIntTagStorage ( MHID, tagname, numvals, ent_type, gdofel)
501502
if (ierr > 0 ) &
502-
call endrun('Error: fail to set globalDOFs tag for coarse elements')
503+
call abortmp('Error: fail to set globalDOFs tag for coarse elements')
503504
endif
504505

505506
! set the global ids for coarse vertices the same as corresponding fine vertices
506507
ent_type = 0 ! vertex type
507508
if ( nverts_c > 0 ) then
508509
ierr = iMOAB_SetIntTagStorage ( MHID, newtagg, nverts_c , ent_type, vdone_c)
509510
if (ierr > 0 ) &
510-
call endrun('Error: fail to set GLOBAL_DOFS tag values')
511+
call abortmp('Error: fail to set GLOBAL_DOFS tag values')
511512
endif
512513

513514
ierr = iMOAB_UpdateMeshInfo(MHID)
514515
if (ierr > 0 ) &
515-
call endrun('Error: fail to update mesh info')
516+
call abortmp('Error: fail to update mesh info')
516517
#ifdef MOABDEBUG
517518
! write out the mesh file to disk, in parallel
518519
outfile = 'wholeATM.h5m'//C_NULL_CHAR
519520
wopts = 'PARALLEL=WRITE_PART'//C_NULL_CHAR
520521
ierr = iMOAB_WriteMesh(MHID, outfile, wopts)
521522
if (ierr > 0 ) &
522-
call endrun('Error: fail to write the mesh file')
523+
call abortmp('Error: fail to write the mesh file')
523524
#endif
524525

525526
if (fv_nphys > 0 ) then
@@ -629,6 +630,8 @@ subroutine create_moab_meshes(par, elem)
629630
! reuse moab_vert_coords for coordinates of pg mesh
630631
! the first nverts_c coords are the same as coarse mesh; but we do create new
631632
allocate(vdone_pg(nverts_pg))
633+
else
634+
allocate(vdone_pg(1))
632635
endif
633636
do iv = 1, nverts_c
634637
vdone_pg(iv) = vdone_c(iv) ! also the coordinates will be the same !!
@@ -737,7 +740,7 @@ subroutine create_moab_meshes(par, elem)
737740
if ( nverts_pg > 0 ) then
738741
ierr = iMOAB_CreateVertices(MHPGID, dimcoord, dimen, moab_vert_coords)
739742
if (ierr > 0 ) &
740-
call endrun('Error: fail to create MOAB vertices ')
743+
call abortmp('Error: fail to create MOAB vertices ')
741744
endif
742745
! num_el = nelem_pg *
743746
mbtype = 3 ! quadrilateral
@@ -747,61 +750,60 @@ subroutine create_moab_meshes(par, elem)
747750
if ( nelem_pg > 0 ) then
748751
ierr = iMOAB_CreateElements( MHPGID, nelem_pg, mbtype, nve, moabconn_pg, block_ID );
749752
if (ierr > 0 ) &
750-
call endrun('Error: fail to create MOAB elements')
753+
call abortmp('Error: fail to create MOAB elements')
751754
endif
752755
tagname='GLOBAL_ID'//C_NULL_CHAR
753756
tagtype = 0 ! dense, integer
754757
numco = 1
755758
ierr = iMOAB_DefineTagStorage(MHPGID, tagname, tagtype, numco, tagindex )
756759
if (ierr > 0 ) &
757-
call endrun('Error: fail to retrieve GLOBAL id tag')
760+
call abortmp('Error: fail to retrieve GLOBAL id tag')
758761

759762
! now set the values
760763
ent_type = 0 ! vertex type
761764
if ( nverts_pg > 0 ) then
762765
ierr = iMOAB_SetIntTagStorage ( MHPGID, tagname, nverts_pg , ent_type, vdone_pg)
763766
if (ierr > 0 ) &
764-
call endrun('Error: fail to set global id tag for vertices')
767+
call abortmp('Error: fail to set global id tag for vertices')
765768
endif
766769
! set global id tag for pg2 elements, too; they will start at nets=1, end at nete=nelemd*4
767770
ent_type = 1 ! now set the global id tag on elements
768771
if ( nelem_pg > 0 ) then
769772
ierr = iMOAB_SetIntTagStorage ( MHPGID, tagname, nelem_pg , ent_type, elemids)
770773
if (ierr > 0 ) &
771-
call endrun('Error: fail to set global id tag for edges')
774+
call abortmp('Error: fail to set global id tag for edges')
772775
endif
773776

777+
! this involves a collective, vdone_pg can be empty
774778
ierr = iMOAB_ResolveSharedEntities( MHPGID, nverts_pg, vdone_pg );
775779
if (ierr > 0 ) &
776-
call endrun('Error: fail to resolve shared ents for pg2 mesh')
780+
call abortmp('Error: fail to resolve shared ents for pg2 mesh')
777781

778782
ierr = iMOAB_UpdateMeshInfo(MHPGID)
779783
if (ierr > 0 ) &
780-
call endrun('Error: fail to update mesh info for pg2 mesh')
784+
call abortmp('Error: fail to update mesh info for pg2 mesh')
781785
#ifdef MOABDEBUG
782786
! write out the mesh file to disk, in parallel
783787
outfile = 'wholeATM_PG2.h5m'//C_NULL_CHAR
784788
wopts = 'PARALLEL=WRITE_PART'//C_NULL_CHAR
785789
ierr = iMOAB_WriteMesh(MHPGID, outfile, wopts)
786790
if (ierr > 0 ) &
787-
call endrun('Error: fail to write the mesh file')
791+
call abortmp('Error: fail to write the mesh file')
788792
#endif
789793
endif ! only valid for pg == 2
790794
if ( nelemd > 0 ) then
791795
deallocate (local_cell_gids)
792796
deallocate (indx_cell)
793797
deallocate (edge) !
794798
deallocate(moabconn_pg) ! connectivity
795-
deallocate(vdone_pg)
796799
endif
797-
800+
deallocate(vdone_pg) ! this is now always allocated/deallocated, even for no mesh here
798801
endif
799802

800803
! deallocate
801804
if ( nelemd > 0 ) then
802805
deallocate(moabvh)
803806
deallocate(moabconn) ! do not keep it anymore, we are not setting another tag on fine mesh
804-
deallocate(vdone)
805807
deallocate(gdofel)
806808
deallocate(indx)
807809
deallocate(elemids)
@@ -810,6 +812,7 @@ subroutine create_moab_meshes(par, elem)
810812
deallocate(moabconn_c)
811813
deallocate(vdone_c)
812814
endif
815+
deallocate(vdone) ! we are always allocating this now
813816
! end copy
814817

815818
end subroutine create_moab_meshes

0 commit comments

Comments
 (0)