Skip to content

Expose *_caf_init(), *caf_finalize() #204

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

Closed
amckinstry opened this issue Jun 21, 2016 · 11 comments
Closed

Expose *_caf_init(), *caf_finalize() #204

amckinstry opened this issue Jun 21, 2016 · 11 comments
Assignees

Comments

@amckinstry
Copy link

amckinstry commented Jun 21, 2016

Hi,

I've been experimenting with running CAF under Python using f2py. Its a bit hacky at the moment (proof of concept time) but I can now compile and run CAF programs under Python3 using f2py3.5, OpenCoarrays 1.6.0 and OpenMPI 1.10.3 on Debian.

So I have a Fortran module:

module caftest
contains
  subroutine bar
    implicit none
    integer:: np, me

    np = num_images()
    me = this_image()
    write (*,*) "I am image ", me, " of ", np
  end subroutine bar
end module

caftest.py:

#!/usr/bin/env python3
# hacky setup code here
caftest.bar()

mpiexec -n 2 ./caftest.py
I am image 1 of 2
I am image 2 of 2

To do this, I've needed to call _gfortran_caf_init() and _gfortran_caf_finalize() from the Python / f2py layer, in order to setup mpi_init, etc. But there is no coarray.h, API exposed, so this was a little .. unorthodox. Can they be exposed?

Regards
Alastair McKinstry

@zbeekman zbeekman assigned zbeekman and afanfa and unassigned zbeekman Jun 21, 2016
@zbeekman
Copy link
Collaborator

I'm wondering if it would make sense to expose this in the alternate user interface module (opencoarrays.F90)

@amckinstry
Copy link
Author

@zbeekman I think so, yes.
I've been working in C, but I think I may be able to work directly in Fortran. It'll be two or three weeks before I can work on this properly, though

@rouson
Copy link
Member

rouson commented Jun 25, 2016

Cool stuff! Without checking, I'm pretty sure these are already public functions so they are exposed, but if I'm missing something, let me know.

As an aside, @rasmussn, who is working with us on the source transformation capability, published an article on coarray Python. I wonder if that would be of interest. If so, I'd be very interested in reviving the concept.

@amckinstry
Copy link
Author

Thanks, thats interesting. 2004 is a bit prescient. I'll think about it. At the moment I'm working on examining performance aspects of CAF + MPI3 features. Python wrappers for Fortran code are becoming increasingly frequent, and if CAF becomes more popular, f2py support for CAF is needed.

@afanfa
Copy link
Contributor

afanfa commented Aug 11, 2016

Hello,
is there any progress on this issue?

@amckinstry
Copy link
Author

@afanfa not at the moment, busy with other things.
The public interface (opencoarrays.mod) currently doesn't ship any _init or _finalize methods, so should we ship libcaf.h (and its dependency ./src/libcaf-gfortran-descriptor.h) ?

@zbeekman
Copy link
Collaborator

@amckinstry it should be relatively quick to add public interfaces in opencoarrays.mod... to me that seems like the best solution. However, I think most of us have a lot on our plates at the moment, so the timeline on this is unknown, for now.

@rouson
Copy link
Member

rouson commented Sep 5, 2016

@McKinstry, the requested functions are exposed in src/cafe/opencoarrays.F90 on the caffeinate-opencoarrays branch as part of a plan to facilitate source-to-source translation of Fortran 2008/2015 CAF programs into Fortran 2003 to facilitate compiling CAF programs with non-CAF compilers. If this topic is still of interest to you, then I'll be glad to merge the relevant changes into the master branch so that they can appear in an upcoming release.

@vikramsg
Copy link

I have been experimenting with coarrays and I am thinking of wrapping the code using Python. I would be really interested in knowing how f2py can be used with coarrays.

@amckinstry
Copy link
Author

My current work is a hack that I need to finish cleaning up for submission to numpy. Basically it calls caf_init() and caf_fini(), needed to set things up.
So, the module code above for caftest, then run your python script under mpitest:

#!/usr/bin/env python3

from mpi4py import MPI
# import cafout
comm = MPI.COMM_WORLD

print("rank, size = (%d, %d)" % (comm.rank, comm.size))
# cafout.cafinit(1, "")
from caftest import caftest
caftest.bar()
# cafout.cafend()

The cafout bits are being embedded in the f2py code.

rank, size = (0, 2)
rank, size = (1, 2)
 I am image            1  of            2
 I am image            2  of            2

This is the minimum just to allow CAF programs to be run under Python. The interesting bits are when the arrays are properly handled at the Python level: returning an array view for the coarray so we don't have to sync all the data onto one thread for Python, etc.

@zbeekman zbeekman self-assigned this Nov 10, 2016
@zbeekman
Copy link
Collaborator

The public interface (opencoarrays.mod) currently doesn't ship any _init or _finalize methods, so should we ship libcaf.h (and its dependency ./src/libcaf-gfortran-descriptor.h) ?

@amckinstry just to clarify, by "ship" you mean install these into "/include" or something like that? One concern that I have about this is that this will create a tighter coupling with the CAF implementation, and violates some principles of data hiding and encapsulation. My preference is to put it into opencoarrays.mod but this is a little bit less striaight forward than I initially thought due to the lack of standardization of preprocessing in Fortran. (One must calculate the function name prefixes....)

zbeekman added a commit that referenced this issue Nov 11, 2016
 Fixes #204
 At configure time, choose whether to expose the caf_init and
 caf_finalize functions in the opencoarrays (extension) module.
zbeekman added a commit that referenced this issue Nov 11, 2016
 Fixes #204
 At configure time, choose whether to expose the caf_init and
 caf_finalize functions in the opencoarrays (extension) module.
@ghost ghost added the needs-review label Nov 11, 2016
zbeekman added a commit that referenced this issue Nov 11, 2016
 Fixes #204
 At configure time, choose whether to expose the caf_init and
 caf_finalize functions in the opencoarrays (extension) module.
zbeekman added a commit that referenced this issue Nov 12, 2016
 Fixes #204
 At configure time, choose whether to expose the caf_init and
 caf_finalize functions in the opencoarrays (extension) module.
zbeekman added a commit that referenced this issue Nov 12, 2016
…finalize

Expose caf_init and caf_finalize in module to allow use with f2py

Fixes #204
@ghost ghost removed the needs-review label Nov 12, 2016
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

5 participants