j3-fortran / fortran_proposals

Proposals for the Fortran Standard Committee
178 stars 15 forks source link

allow immediate return from collective subroutines #272

Open brandongc opened 2 years ago

brandongc commented 2 years ago

This is analogous to the widely used immediate (or non-blocking) collectives in MPI.

type(event_type) :: a
call co_sum(x, event = a) ! "Immediate return" like MPI_Iallreduce
call do_something_independent(y)
event wait (a) ! can't use x until co_sum is done

Benefits:

rouson commented 2 years ago

Presumably this will inspire us to remove the requirement that objects of event_type must be coarrays, which is constraint C1604 in the Fortran 2018 standard.

ThemosTsikas commented 1 year ago

I am thinking that this could generalize to any CALL statement with the introduction of the syntax

CALL [ ( call-control-spec-list ) ] procedure-designator [ ( [ actual-arg-spec-list ] ) ] call-control-spec is [ EVENT = ] event-variable

There will be a need for a new intrinsic function (CALL?) with no arguments whose return value is the event-variable (or a pointer associated with it?) of the currently executing CALL.

This is just musing. Do you know of any work on similar ideas?

everythingfunctional commented 1 year ago

There will be a need for a new intrinsic function (CALL?) with no arguments whose return value is the event-variable (or a pointer associated with it?) of the currently executing CALL.

Can you elaborate on this? I'm not sure I'm following. Couldn't there be multiple currently executing "calls"? I.e.

type(event_type) :: a, b
call co_sum(x, event=a)
call co_sum(y, event=b)
! Do something independent of x and y
event wait (a)
! do something with x
event wait (b)
! do something with y

This is just musing. Do you know of any work on similar ideas?

https://github.com/jeffhammond/j3/blob/main/asynchronous_tasks.md is possibly related.

ThemosTsikas commented 1 year ago
type(event_type) :: a, b
call (EVENT=a) process(x)
call (EVENT=b) process(y)
! Do something independent of x and y
event wait (a)
! do something with x
event wait (b)
! do something with y

During execution of "process(x)"/"process(y)", the intrinsic function "CALL()" returns a/b, respectively.

everythingfunctional commented 1 year ago

Interesting idea. Does that imply

FortranFan commented 1 year ago
  • new intrinsic CALL function (I might give that a different name)

You mean CALL statement?

Re: "different name" - CO_CALL? !!!: :-))

ThemosTsikas commented 1 year ago

block-stmt is [ block-construct-name : ] BLOCK [ ( call-control-spec-list )

if you must!

Instead of an intrinsic function, an intrinsic subroutine would allow for EVENT= and STAT= arguments, to handle the case where no event has been associated by the executing BLOCK or SUBROUTINE.