Skip to content

Commit 7934034

Browse files
committed
Merge branch 'jonbob/mpas-framework/fix-log-abort' (PR #7457)
Fix the abort routines in mpas-framework to use shr_sys_abort when coupled Fix the abort routines in mpas-framework so that log_abort calls mpas_dmpar_global_abort and mpas_dmpar_global_abort itself uses shr_sys_abort when running as a coupled model. Fixes #7447 [BFB]
2 parents 203df99 + e889683 commit 7934034

File tree

3 files changed

+37
-30
lines changed

3 files changed

+37
-30
lines changed

components/mpas-framework/src/framework/framework.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# framework
2+
list(APPEND CPPDEFS "-Dcoupled")
23
list(APPEND COMMON_RAW_SOURCES
34
framework/mpas_kind_types.F
45
framework/mpas_framework.F

components/mpas-framework/src/framework/mpas_abort.F

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ subroutine mpas_dmpar_global_abort(mesg, deferredAbort)!{{{
2929
use mpas_kind_types, only : StrKIND
3030
use mpas_io_units, only : mpas_new_unit
3131
use mpas_threading, only : mpas_threading_get_thread_num
32+
33+
#ifdef coupled
34+
use shr_sys_mod, only : shr_sys_abort
35+
#endif
3236

3337
#ifdef _MPI
3438
#ifndef NOMPIMOD
@@ -44,7 +48,7 @@ subroutine mpas_dmpar_global_abort(mesg, deferredAbort)!{{{
4448
#endif
4549
#endif
4650

47-
character(len=*), intent(in) :: mesg !< Input: Abort message
51+
character(len=*), intent(in), optional :: mesg !< Input: Abort message
4852
logical, intent(in), optional :: deferredAbort !< Input: Defer call to abort until later
4953

5054
integer :: threadNum
@@ -63,40 +67,46 @@ subroutine mpas_dmpar_global_abort(mesg, deferredAbort)!{{{
6367
local_deferredAbort = .false.
6468
end if
6569

66-
threadNum = mpas_threading_get_thread_num()
70+
if (present(mesg)) then
71+
threadNum = mpas_threading_get_thread_num()
6772

6873
#ifdef _MPI
69-
call MPI_Comm_rank(MPI_COMM_WORLD, my_proc_id, mpi_ierr)
70-
call MPI_Comm_size(MPI_COMM_WORLD, nprocs, mpi_ierr)
71-
if (nprocs < 1E4) then
72-
write(errorFile,fmt='(a,i4.4,a)') 'log.', my_proc_id, '.abort'
73-
else if (nprocs < 1E5) then
74-
write(errorFile,fmt='(a,i5.5,a)') 'log.', my_proc_id, '.abort'
75-
else if (nprocs < 1E6) then
76-
write(errorFile,fmt='(a,i6.6,a)') 'log.', my_proc_id, '.abort'
77-
else if (nprocs < 1E7) then
78-
write(errorFile,fmt='(a,i7.7,a)') 'log.', my_proc_id, '.abort'
79-
else if (nprocs < 1E8) then
80-
write(errorFile,fmt='(a,i8.8,a)') 'log.', my_proc_id, '.abort'
81-
else
82-
write(errorFile,fmt='(a,i9.9,a)') 'log.', my_proc_id, '.abort'
83-
end if
74+
call MPI_Comm_rank(MPI_COMM_WORLD, my_proc_id, mpi_ierr)
75+
call MPI_Comm_size(MPI_COMM_WORLD, nprocs, mpi_ierr)
76+
if (nprocs < 1E4) then
77+
write(errorFile,fmt='(a,i4.4,a)') 'log.', my_proc_id, '.abort'
78+
else if (nprocs < 1E5) then
79+
write(errorFile,fmt='(a,i5.5,a)') 'log.', my_proc_id, '.abort'
80+
else if (nprocs < 1E6) then
81+
write(errorFile,fmt='(a,i6.6,a)') 'log.', my_proc_id, '.abort'
82+
else if (nprocs < 1E7) then
83+
write(errorFile,fmt='(a,i7.7,a)') 'log.', my_proc_id, '.abort'
84+
else if (nprocs < 1E8) then
85+
write(errorFile,fmt='(a,i8.8,a)') 'log.', my_proc_id, '.abort'
86+
else
87+
write(errorFile,fmt='(a,i9.9,a)') 'log.', my_proc_id, '.abort'
88+
end if
8489
#else
85-
errorFile = 'log.abort'
90+
errorFile = 'log.abort'
8691
#endif
8792

88-
if ( threadNum == 0 ) then
89-
call mpas_new_unit(errorUnit)
90-
open(unit=errorUnit, file=trim(errorFile), form='formatted', position='append')
91-
write(errorUnit,*) trim(mesg)
92-
close(errorUnit)
93+
if ( threadNum == 0 ) then
94+
call mpas_new_unit(errorUnit)
95+
open(unit=errorUnit, file=trim(errorFile), form='formatted', position='append')
96+
write(errorUnit,*) trim(mesg)
97+
close(errorUnit)
98+
end if
9399
end if
94100

95101
if (.not. local_deferredAbort) then
102+
#ifdef coupled
103+
call shr_sys_abort('MPAS framework abort')
104+
#else
96105
#ifdef _MPI
97-
call MPI_Abort(MPI_COMM_WORLD, mpi_errcode, mpi_ierr)
106+
call MPI_Abort(MPI_COMM_WORLD, mpi_errcode, mpi_ierr)
98107
#else
99-
stop
108+
stop
109+
#endif
100110
#endif
101111
end if
102112

components/mpas-framework/src/framework/mpas_log.F

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -846,11 +846,7 @@ subroutine log_abort()
846846
deallocate(mpas_log_info % outputLog)
847847
deallocate(mpas_log_info)
848848

849-
#ifdef _MPI
850-
call MPI_Abort(MPI_COMM_WORLD, mpi_errcode, mpi_ierr)
851-
#else
852-
stop
853-
#endif
849+
call mpas_dmpar_global_abort()
854850

855851
!--------------------------------------------------------------------
856852
end subroutine log_abort

0 commit comments

Comments
 (0)