[Dart-dev] [4386] DART/trunk/mpi_utilities: Add a call to finalize_utilities in the mpi finalize routine, to cleanly

nancy at ucar.edu nancy at ucar.edu
Fri Jun 4 11:44:56 MDT 2010


Revision: 4386
Author:   nancy
Date:     2010-06-04 11:44:56 -0600 (Fri, 04 Jun 2010)
Log Message:
-----------
Add a call to finalize_utilities in the mpi finalize routine, to cleanly
shut down the log files.  Also store the program name from init, if given,
so it can be used at finalize time.

Modified Paths:
--------------
    DART/trunk/mpi_utilities/mpi_utilities_mod.f90
    DART/trunk/mpi_utilities/null_mpi_utilities_mod.f90

-------------- next part --------------
Modified: DART/trunk/mpi_utilities/mpi_utilities_mod.f90
===================================================================
--- DART/trunk/mpi_utilities/mpi_utilities_mod.f90	2010-06-03 17:18:30 UTC (rev 4385)
+++ DART/trunk/mpi_utilities/mpi_utilities_mod.f90	2010-06-04 17:44:56 UTC (rev 4386)
@@ -159,6 +159,7 @@
 use utilities_mod, only : register_module, error_handler, & 
                           E_ERR, E_WARN, E_MSG, E_DBG, get_unit, close_file, &
                           set_output, set_tasknum, initialize_utilities,     &
+                          finalize_utilities,                                &
                           nmlfileunit, do_output, do_nml_file, do_nml_term,  &
                           find_namelist_in_file, check_namelist_read
 
@@ -223,6 +224,7 @@
 
 logical :: module_initialized   = .false.
 
+character(len = 129) :: saved_progname = ''
 integer :: head_task             ! default 0, but N-1 if reverse_task_layout true
 logical :: print4status = .true. ! minimal messages for async4 handshake
 
@@ -309,6 +311,16 @@
    call initialize_utilities(progname, alternatename, .false.)
 endif
 
+! save a copy of the initial program name for use in finalize.
+! make sure it is not too long to fit into our variable.
+if (present(progname)) then
+   if (len_trim(progname) <= len(saved_progname)) then
+      saved_progname = trim(progname)
+   else
+      saved_progname = progname(1:len(saved_progname))
+   endif
+endif
+
 if ( .not. module_initialized ) then
    ! Initialize the module with utilities
    call register_module(source, revision, revdate)
@@ -440,6 +452,13 @@
    call finished_task(async)
 endif
 
+! close the log files and write a timestamp
+if (saved_progname /= '') then
+   call finalize_utilities(saved_progname)
+else
+   call finalize_utilities()
+endif
+
 ! For the SGI implementation of MPI in particular, sync before shutting
 ! down MPI.  Once MPI is shut down, no other output can be written; it causes
 ! tasks to hang if they try.  Make sure all tasks are here and ready to

Modified: DART/trunk/mpi_utilities/null_mpi_utilities_mod.f90
===================================================================
--- DART/trunk/mpi_utilities/null_mpi_utilities_mod.f90	2010-06-03 17:18:30 UTC (rev 4385)
+++ DART/trunk/mpi_utilities/null_mpi_utilities_mod.f90	2010-06-04 17:44:56 UTC (rev 4386)
@@ -149,7 +149,7 @@
 use types_mod, only        : r8, digits12
 use utilities_mod, only    : register_module, error_handler,             &
                              initialize_utilities, get_unit, close_file, & 
-                             E_ERR, E_WARN, E_MSG, E_DBG
+                             E_ERR, E_WARN, E_MSG, E_DBG, finalize_utilities
 use time_manager_mod, only : time_type, set_time
 
 
@@ -196,6 +196,8 @@
 
 logical, save :: module_initialized = .false.
 
+character(len = 129) :: saved_progname = ''
+
 character(len = 129) :: errstring
 
 ! Namelist input - placeholder for now; no options yet in this module.
@@ -228,6 +230,14 @@
 
 call initialize_utilities(progname, alternatename)
 
+if (present(progname)) then
+   if (len_trim(progname) < len(saved_progname)) then
+      saved_progname = trim(progname)
+   else
+      saved_progname = progname(1:len(saved_progname))
+   endif
+endif
+
 if ( .not. module_initialized ) then
    ! Initialize the module with utilities
    call register_module(source, revision, revdate)
@@ -258,16 +268,17 @@
  logical, intent(in), optional :: callfinalize
  integer, intent(in), optional :: async
 
-! Shut down MPI cleanly.  This must be done before the program exits; on
-! some implementations of MPI the final I/O flushes are not done until this
-! is called.  The optional argument can prevent us from calling MPI_Finalize,
-! so that user code can continue to use MPI after this returns.  For good
-! coding practice you should not call any other routines in this file
-! after calling this routine.
+! Shut down cleanly.  Call normal utilities finalize if we have actually
+! ever called initialize.  Otherwise there is nothing to do in the null case.
 
 
-if ( .not. module_initialized ) call initialize_mpi_utilities()
+if ( .not. module_initialized ) return
 
+if (saved_progname /= '') then
+   call finalize_utilities(saved_progname)
+else
+   call finalize_utilities()
+endif
 
 end subroutine finalize_mpi_utilities
 


More information about the Dart-dev mailing list