Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for OpenMP or Co-array Fortran #7

Open
koshMer opened this issue Oct 22, 2021 · 3 comments
Open

Support for OpenMP or Co-array Fortran #7

koshMer opened this issue Oct 22, 2021 · 3 comments

Comments

@koshMer
Copy link

koshMer commented Oct 22, 2021

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?

@tchlux
Copy link
Owner

tchlux commented Oct 26, 2021

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.

@tchlux
Copy link
Owner

tchlux commented Oct 26, 2021

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.

@koshMer
Copy link
Author

koshMer commented Oct 27, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants