Skip to content

Commit 9552a2a

Browse files
authored
Edits to k-buffering and new features in pp_ser.py (#245)
This PR contains two minor changes to the k-buffering feature used by `pp_ser.py` and implemented in `utils_ppser_kbuff.f90` (increase in maximum number of buffers, more verbose error message in case of a problem) and adds two new features to `pp_ser.py`. For the latter, the changes are located in `pp_ser.py` and `utils_ppser.f90` only and entail: - When initializing `pp_ser.py` with reference data one can specify another directory where the data is located. If this is not available, new data will be serialized into the same directory as the reference data which can lead to conflicts or corrupt data. - Up to now, the directive syntax for specifying a savepoint was `!$ser savepoint gugus` where gugus was the name of the savepoint. This syntax does not allow the dynamic generation of savepoint names (e.g. from runtime information such as timestep or a unique ID). A new command line option to `pp_ser.py` named `-s` or `--sp-as-var` allows to use `!$ser savepoint "gugus"` or `!$ser savepoint my_string` where `my_string` is a variable.
1 parent 88ac7cf commit 9552a2a

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

src/serialbox-fortran/utils_ppser.f90

+13-6
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,27 @@ MODULE utils_ppser
6363

6464
!============================================================================
6565

66-
SUBROUTINE ppser_initialize(directory, prefix, mode, prefix_ref, mpi_rank, rprecision, rperturb, realtype, archive, unique_id)
66+
SUBROUTINE ppser_initialize(directory, prefix, mode, directory_ref, prefix_ref, &
67+
mpi_rank, rprecision, rperturb, realtype, archive, unique_id)
6768
CHARACTER(LEN=*), INTENT(IN) :: directory, prefix
6869
INTEGER, OPTIONAL, INTENT(IN) :: mode
69-
CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: prefix_ref
70+
CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: directory_ref, prefix_ref ! use a different serializer for reading (optional)
7071
INTEGER, OPTIONAL, INTENT(IN) :: mpi_rank
7172
REAL(KIND=8), OPTIONAL, INTENT(IN) :: rprecision, rperturb
7273
INTEGER, OPTIONAL, INTENT(IN) :: realtype
7374
CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: archive
7475
LOGICAL, INTENT(IN), OPTIONAL :: unique_id
7576

77+
CHARACTER(LEN=256) :: dir_ref
7678
CHARACTER(LEN=1), DIMENSION(128) :: buffer
7779
CHARACTER(LEN=15) :: suffix
7880
INTEGER :: intvalue
7981

82+
IF (PRESENT(directory_ref)) THEN
83+
dir_ref = directory_ref
84+
ELSE
85+
dir_ref = directory
86+
ENDIF
8087

8188
! Initialize serializer and savepoint
8289
IF ( .NOT. ppser_initialized ) THEN
@@ -102,15 +109,15 @@ SUBROUTINE ppser_initialize(directory, prefix, mode, prefix_ref, mpi_rank, rprec
102109
ppser_hasref = .true.
103110
IF ( PRESENT(mpi_rank) ) THEN
104111
IF ( PRESENT(archive) ) THEN
105-
CALL fs_create_serializer(directory, TRIM(prefix_ref)//TRIM(suffix), 'r', ppser_serializer_ref, archive)
112+
CALL fs_create_serializer(dir_ref, TRIM(prefix_ref)//TRIM(suffix), 'r', ppser_serializer_ref, archive)
106113
ELSE
107-
CALL fs_create_serializer(directory, TRIM(prefix_ref)//TRIM(suffix), 'r', ppser_serializer_ref)
114+
CALL fs_create_serializer(dir_ref, TRIM(prefix_ref)//TRIM(suffix), 'r', ppser_serializer_ref)
108115
END IF
109116
ELSE
110117
IF ( PRESENT(archive) ) THEN
111-
CALL fs_create_serializer(directory, TRIM(prefix_ref), 'r', ppser_serializer_ref, archive)
118+
CALL fs_create_serializer(dir_ref, TRIM(prefix_ref), 'r', ppser_serializer_ref, archive)
112119
ELSE
113-
CALL fs_create_serializer(directory, TRIM(prefix_ref), 'r', ppser_serializer_ref)
120+
CALL fs_create_serializer(dir_ref, TRIM(prefix_ref), 'r', ppser_serializer_ref)
114121
END IF
115122
END IF
116123
END IF

src/serialbox-fortran/utils_ppser_kbuff.f90

+4-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ MODULE utils_ppser_kbuff
5959
LOGICAL, ALLOCATABLE :: ok(:) ! has this k-level been written?
6060
END TYPE kbuff_type
6161

62-
INTEGER, PARAMETER :: max_kbuff = 999 ! increase in case you get errors
62+
INTEGER, PARAMETER :: max_kbuff = 9999 ! increase in case you get errors
6363
TYPE(kbuff_type) :: kbuff(max_kbuff) ! array containing buffers
6464

6565
! overload interface for different types and dimensions
@@ -113,6 +113,9 @@ SUBROUTINE finalize_kbuff()
113113
DO idx = 1, max_kbuff
114114
IF (kbuff(idx)%in_use) THEN
115115
WRITE(0,*) 'ERROR in utils_ppser_kbuff: finalize called before all buffers have been flushed'
116+
WRITE(0,*) 'savepoint_name: ', TRIM(kbuff(idx)%savepoint_name)
117+
WRITE(0,*) 'name of partially empty field: ', TRIM(kbuff(idx)%fieldname)
118+
WRITE(0,*) 'vertical indices filled boolean: ', kbuff(idx)%ok(:)
116119
STOP
117120
END IF
118121
kbuff(idx)%fieldname = ""

src/serialbox-python/pp_ser/pp_ser.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class PpSer:
7777

7878
def __init__(self, infile, outfile='', ifdef='SERIALIZE', real='ireals',
7979
module='m_serialize', identical=True, verbose=False,
80-
acc_prefix=True, acc_if='', modules=''):
80+
acc_prefix=True, acc_if='', modules='', sp_as_var=False):
8181

8282
# public variables
8383
self.verbose = verbose
@@ -89,6 +89,7 @@ def __init__(self, infile, outfile='', ifdef='SERIALIZE', real='ireals',
8989
self.identical = identical # write identical files (no preprocessing done)?
9090
self.acc_prefix = acc_prefix # generate preprocessing marco for ACC_PREFIX
9191
self.acc_if = acc_if # generate IF clause after OpenACC update
92+
self.sp_as_var = sp_as_var # Syntax for savepoints using variable instead of string
9293

9394
# setup (also public)
9495
self.methods = {
@@ -460,7 +461,10 @@ def __ser_savepoint(self, args):
460461

461462
self.__calls.add(self.methods['savepoint'])
462463
self.__calls.add(self.methods['spinfo'])
463-
l += tab + 'call ' + self.methods['savepoint'] + '(\'' + name + '\', ppser_savepoint)\n'
464+
if not self.sp_as_var:
465+
l += tab + 'call ' + self.methods['savepoint'] + '(\'' + name + '\', ppser_savepoint)\n'
466+
else:
467+
l += tab + 'call ' + self.methods['savepoint'] + '(' + name + ', ppser_savepoint)\n'
464468
for k, v in zip(keys, values):
465469
l += tab + 'call ' + self.methods['spinfo'] + '(ppser_savepoint, \'' + k + '\', ' + v + ')\n'
466470

@@ -1057,6 +1061,8 @@ def parse_args():
10571061
default='', type=str, dest='acc_if')
10581062
parser.add_option('-m', '--module', help='Extra MODULE to be add to the use statement',
10591063
default='', type=str, dest='modules')
1064+
parser.add_option('-s', '--sp-as-var', help='Savepoint specified as variable instead of string',
1065+
default=False, action='store_true', dest='sp_as_var')
10601066
(options, args) = parser.parse_args()
10611067
if len(args) < 1:
10621068
parser.error('Need at least one source file to process')
@@ -1098,5 +1104,5 @@ def parse_args():
10981104
print('Processing file', infile)
10991105
ser = PpSer(infile, real='wp', outfile=outfile, identical=(not options.ignore_identical),
11001106
verbose=options.verbose, acc_prefix=options.acc_prefix, acc_if=options.acc_if,
1101-
modules=options.modules)
1107+
modules=options.modules, sp_as_var=options.sp_as_var)
11021108
ser.preprocess()

0 commit comments

Comments
 (0)