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

problems in Example 19.11 #739

Open
jeffhammond opened this issue Aug 16, 2023 · 4 comments
Open

problems in Example 19.11 #739

jeffhammond opened this issue Aug 16, 2023 · 4 comments
Assignees
Labels
chap-bindings Language Bindings Chapter Committee mpi-4.2 wg-fortran Fortran Working Group

Comments

@jeffhammond
Copy link
Member

jeffhammond commented Aug 16, 2023

Problem

  1. In Example 19.11, MPI_X_TYPE_COMMIT violates 2.6.2 and 2.6.3. I understand that this is an example for implementers of how to implement the Fortran API, but there's no need for it to use the MPI_ namespace and doing so may give users the wrong idea.

  2. Furthermore, the entire premise of this example is common but unspecified behavior of Fortran compilers, and I do not see the point of such an example, particularly when the features to write such code in a compliant manner has been in the Fortran standard for 20 years.

  3. A lesser problem is that this example contains the ubiquitous Fortran anti-pattern of a RETURN statement at the end of the subroutine.

Proposal

I would prefer to remove this example for multiple reasons, but if folks insist on keeping it, it should be modified to be compliant with some version of the Fortran language, ideally Fortran 2003.

Changes to the Text

This is a standard-compliant example:

function MPI_Type_commit(datatype) result(ierr)
  implicit none
  interface
    integer function C_MPI_Type_commit(datatype) &
            bind(C,name="C_MPI_Type_commit")
      integer, intent(inout) :: datatype
      integer :: ierr
    end function
  end interface
  integer, intent(inout) :: datatype
  integer :: ierr
  ierr = C_MPI_Type_commit(datatype)
end function MPI_Type_commit
MPI_Fint C_MPI_Type_commit(MPI_Fint * f_handle)
{
   MPI_Datatype datatype = MPI_Type_f2c(*f_handle);
   MPI_Fint ierr = MPI_Type_commit(&datatype);
   *f_handle = MPI_Type_c2f(datatype);
   return ierr;
}

Impact on Implementations

None. No one depends on this example to implement MPI.

Impact on Users

Users won't be confused into writing bad code.

References and Pull Requests

Programs must not declare names (identifiers), e.g., for variables, functions, constants, types, or macros, beginning with any prefix of the form MPI_, where any of the letters are either upper or lower case.

Programs must not declare names, e.g., for variables, subroutines, functions, parameters, derived types, abstract interfaces, or modules, beginning with the prefix MPI_.

@jeffhammond jeffhammond added the wg-fortran Fortran Working Group label Aug 16, 2023
@wesbland
Copy link
Member

@jeffhammond - Is this intended as a 4.1 RC review or for changes in the future? Trying to figure out the target here.

@jeffhammond
Copy link
Member Author

I don't care. The example sucks and should be removed as soon as possible.

@wesbland wesbland added chap-bindings Language Bindings Chapter Committee mpi-4.1 For inclusion in the MPI 4.1 standard labels Sep 13, 2023
@RolfRabenseifner
Copy link

The example was added to make clear, that for the implementation of the Fortran interface through wrappers, one widle portable possibility is that the wrapper is a combination of two wrappers: Wrapper in Fortran calls a stub in C, which then calls the C MPI routine. Especially, the Fortran mapping of Fortran routine names in the mpif.h is automatically resolved.

@jeffhammond
Copy link
Member Author

I understand the historical purpose. But since F03, there is a better way, which is actually standard.

@wesbland wesbland added mpi-4.2 and removed mpi-4.1 For inclusion in the MPI 4.1 standard labels Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chap-bindings Language Bindings Chapter Committee mpi-4.2 wg-fortran Fortran Working Group
Projects
Status: To Do
Status: To Do
Development

No branches or pull requests

4 participants