fmodpy
fmodpy copied to clipboard
Support for OpenMP or Co-array Fortran
Hi, I was wondering whether your wrapper has support for openMP or co-array fortran?
i tried running the .f90 program:
module hello_images
implicit none
contains
subroutine hello()
print *, "I am iamge", this_image(), "of", num_images()
end subroutine hello
end module hello_images
with the following python program
import fmodpy
code = fmodpy.fimport("hello_images.f90",f_compiler = "caf")
code.hello_images.hello()
This gives me an output of I am iamge 0 of 0
Usually, when using co-array fortran, one would supply the number of images when running the program.
For Example: cafrun -n program
Is something like this possible with your wrapper?
I use OpenMP all the time, there's a preconfigured argument omp=True that will add the -fopenmp flag for OpenMP compilation! Of course all of that is customizable, and you can see and control all the different internals through fmodpy.configure()!
And hmm, presumably cafrun communicates with the compiled program somehow, probably by setting environment variables. If you find out how the communication is done, then you should be able to mimic that in the python runtime! Let me look around.
Edit: I looked around and I don't see any immediately available docs that explain how cafrun works in conjunction with a caf compiler. The core concept to remember is, fmodpy is all about compiling Fortran code into something that can be imported in Python. That means that Python is always the parent process. As long as you can make this work in a way that any other C code could link against it, then it can work with Python.
Looks like the number of processes being launched can be controlled with a hosts file: https://www.open-mpi.org/doc/v3.0/man1/mpiexec.1.php
But still, seems like the logic in the process launcher mpiexec (or cafrun) is necessary to establish the (MPI) comms network. If you want this to work from Python, you're going to have to find a way to include that setup in the compiled program that you import into Python. That will probably look like including the source code for cafrun within your executable, so that when it is compiled it can be executed as one single code.
Thanks for your help! When I have some spare time I will look into that, though that's a bit over my head. I'll leave this open for now - if that's ok ^^ - and come back to it when I have something to share.