Version 2 (modified by lnerger, 10 years ago) (diff)


Adapting a model's parallelization for PDAF

PDAF uses the MPI standard for the parallelization, like many numerical models. In the description below, we assume that the model is parallelized using MPI.

If the parallelization possibilities of PDAF should be used, the parallelization for parallel ensemble integrations (below denoted as model tasks) has to be initialized. If the numerical model itself is parallelized, this parallelization has to be adapted and modified for the 2-level parallelization of the data assimilation system generated by adding PDAF to the model.

The parallel region of an MPI parallel program is initialized by calling MPI_init. MPI uses communicators to define sets of parallel processes. By calling MPI_init, the communicator MPI_COMM_WORLD is initialized. This communicator contains all processes of the MPI-parallel program. Often it is sufficient to conduct all parallel communication using this communicator. Thus, numerical models often use only MPI_COMM_WORLD to control all communication. However, this approach will not allow for parallel model tasks. In order to allow parallel model tasks, it is required to replace MPI_COMM_WORLD by an alternative communicator that is split for the model tasks. We will denote this communicator COMM_MODEL. Frequently the parallelization is initialized in the model by the lines:

      CALL MPI_Init(ierr)
      CALL MPI_Comm_Rank(MPI_COMM_WORLD, rank, ierr)
      CALL MPI_Comm_Size(MPI_COMM_WORLD, size, ierr)

Subsequently, one can define COMM_MODEL by adding


In addition, the variable COMM_MODEL has to be declared in a way such that all routines using the communicator can access it. The parallelization variables of the model are frequently hold in a module. In this case, it is easiest to add COMM_MODEL as an integer variable here. (If the model itself is not parallelized, one has to add the call to MPI_Init ot the program, e.g. to the routine init_parallel_pdaf, if the parallelization features of PDAF should be used.) Having defined the communicator COMM_model, the communicator MPI_COMM_WORLD has to be replaced by COMM_MODEL in all routines that perform MPI communication. These changes should not influence the model itself. Thus, after these changes, one should ensure that the model compiles and runs correctly.

Having replaced MPI_COMM_WORLD by COMM_MODEL enables to split the model integration into parallel model tasks. For this, the communicator COMM_MODEL has to be redefined. This is performed by the routine init_parallel_init, which is supplied with the PDAF package. The routine should be added to the model usually directly after the initialization of the parallelization described above. The routine init_parallel_pdaf also defines a communicator COMM_FILTER, which includes the processes that perform the analysis step of the filter, and COMM_couple, which couples the processes in COMM_FILTER with those in COMM_MODEL. The provided routine init_paralllel_init is a template implementation. Thus, it has to be adjusted for the model under consideration. In particular one needs to ensure that the routine knows the variables COMM_MODEL as well as 'rank' and 'size' (See the initialization example above. These variables might have different names in a model). This can be done by adding a USE statement in init_parallel_pdaf, if the model defines these variables in a module. The routine init_parallel_pdaf splits the communicator MPI_COMM_WORLD and defines a set of communicator COMM_MODEL. In addition, the variables npes_world and mype_world are defined. If the model uses different names for these quentities, like 'rank' and 'size', the model-internal variables should be re-initialized at the end of init_parallel_pdaf. The routine defined several more variables. In the example implementation these are declared and held in the model mod_parallel. It would be useful to use this module with the model code as some of these variables are required when the initialization routine of PDAF (PDAF_init) is called.

This completes the adaptation of the parallelization. The compilation of the model has to be adjusted for the added files holding the routine init_parallel_pdaf and the model mod_parallel. One can test the extension by running the compiled model. It should run as without these changes, as the mod_parallel defines by default that a single model task is executed. To test parallel model tasks one has to set the variable n_modeltasks to a value larger than one. Now, the model will execute parallel model tasks. This can result in the following effects:

  • The standard screen output of the model can by shown multiple times. This is due to the fact that often the process with rank=0 perform screen output. By splitting the communicator COMM_MODEL, there will be as many processes with rank 0 as there are model tasks. In addition, each model task might write file output. This can lead to the case that several processes try to generate the same file or try to write into the same file. In the extreme case this can result in a program crash. For this resong, it might be useful to restrict the file output to a single model task. This might be implemented using the variable 'task_id' tha tis initialized by init_parallel_pdaf and hold the index of the model task ranging from 1 to n_modeltasks. (For the ensemble assimilation, it can be useful to switch off the regular file output of the model completely. As each model tasks holds only a single member of the ensemble, this output might not be useful. In this case, the file output for the state estimate and perhaps all ensemble members should be done in the pre/poststep routine of the assimilation system.)