Discussion:
[OMPI users] confusion in place to initialize mpi environment
Lily H
2017-07-04 15:19:15 UTC
Permalink
Hello,
I’m currently working on converting a serial Magneto-friction fortran code into parallel version. The code is composed of one main program and three modules which contain all the sub functions and parameters needed. When running the serial code, the procedure is to compile the modules first, then use the modules.o, program.o files to generate the program executable. Now it is parallel, the sub functions in module need to be changed into parallel version, specifically, loops that involve setting up and updating the variables need to change from looping all over the grid to looping section of grid specified by the taskid. From various examples I’ve found, the standard way to parallelize a piece of code is to initialize the mpi environment in main program, separate master and worker tasks and collect them in the end, finalize the mpi environment. However since the modules are compiled prior to main program, I was wondering if I should initialize mpi environment in module instead. In other words, will I be able to compile the modules if it only includes the mpif.h and uses certain mpi variables such as taskid and num_tasks? (I won’t need to call any mpi functions in the sub function, only need the taskid to specify loop start and end). If the answer is no, is there anyway I can pass parameters defined inside main program into the module it is using?
I hope my question is clear enough. Any help is appreciated!

Thanks!

Han

Loading...