@@ -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
0 commit comments