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

Add a module that replaces the non-coarray parallel features with MPI when necessary #84

Open
rouson opened this issue May 10, 2024 · 3 comments · May be fixed by #85
Open

Add a module that replaces the non-coarray parallel features with MPI when necessary #84

rouson opened this issue May 10, 2024 · 3 comments · May be fixed by #85
Assignees

Comments

@rouson
Copy link
Member

rouson commented May 10, 2024

Such a module could export functionality through which parallel programs could switch parallel programming models at compile-time based on generic interfaces:

module parallelism_m
  !! Use compile-time polymophism to select wrappers for native or alternative parallel progromming models
  implicit none

  private
  public :: mpi_t ! alternative programming models

  public :: error_stop_   ! execute error stop or print stop code, invoke MPI_Finalize, and invoke MPI_Abort
  public :: co_broadcast_ ! call co_broadcast or MPI_Bcast
  public :: co_sum_       ! call co_sum or MPI_Reduce
  public :: co_min_       ! call co_min or MPI_Reduce
  public :: co_max_       ! call co_max or MPI_Reduce
  public :: co_reduce_    ! call co_reduce or MPI_Reduce
  public :: init_         ! do nothing or invoke MPI_Init
  public :: finalize_     ! do nothing or a invoke MPI_Finalize
  public :: num_images_   ! invoke num_images() or call MPI_Comm_Size
  public :: sync_all_     ! execute sync all or invoke MPI_Barrier
  public :: stop_         ! execute stop or print stop code, invoke MPI_Finalize, and then execute stop
  public :: this_image_   ! invoke this_image() or call MPI_Comm_Rank

  type mpi_t
  end type

  interface error_stop_

    module subroutine error_stop_native_integer(code)
      implicit none
      integer, intent(in) :: code
    end subroutine 

    module subroutine error_stop_mpi_integer(mpi, code)
      implicit none
      type(mpi_t) mpi
      integer, intent(in) :: code
    end subroutine 

    module subroutine error_stop_native_character(code)
      implicit none
      character(len=*), intent(in) :: code
    end subroutine 

    module subroutine error_stop_mpi_character(mpi, code)
      implicit none
      character(len=*), intent(in) :: code
    end subroutine 

  end interface

  interface init_

    module subroutine init_native()
      implicit none
    end subroutine 

    module subroutine init_mpi(mpi)
      implicit none
      type(mpi_t) mpi
    end subroutine 

  end interface

  interface finalize_

    module subroutine finalize_native()
      implicit none
    end subroutine 

    module subroutine finalize_mpi(mpi)
      implicit none
      type(mpi_t) mpi
    end subroutine 

  end interface

  interface this_image_

    integer module function this_image_native()
      implicit none
    end function 

    integer module function this_image_mpi(mpi)
      implicit none
      type(mpi_t) mpi
    end function 

  end interface

  interface num_images_

    integer module function num_images_native()
      implicit none
    end function 

    integer module function num_images_mpi(mpi)
      implicit none
      type(mpi_t) mpi
    end function 

  end interface

  ! ...

end module parallelism_m
@rouson
Copy link
Member Author

rouson commented May 10, 2024

@ktras I assume the MPI procedures are impure. In the Assert library, we can just not report the image on which an assertion fails so there won't be any need for this_image(). Otherwise, if we made the assertion subroutine impure, it would have a nasty domino effect across hundreds of procedures in multiple projects.

@rouson
Copy link
Member Author

rouson commented May 10, 2024

For this to be general, we would need to handle every combination of rank and intrinsic type, but I think if we just do ranks 0-2, it might suffice for present purposes. Handling derived type arguments for co_broadcast will be interesting.

@rouson rouson linked a pull request May 14, 2024 that will close this issue
1 task
@rouson
Copy link
Member Author

rouson commented May 14, 2024

@ktras I have a initial start on a draft of what we need in PR #85 with a comment containing a "To Do" item describing an issue that needs to be resolved. I'm hoping you can work on finishing the procedure definitions and fixing the issue described in the "To Do" section of the comment.

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

Successfully merging a pull request may close this issue.

2 participants