X-Mailer: QUALCOMM Windows Eudora Pro Version 4.2.2 Date: Thu, 07 Jun 2001 08:50:21 -0500 To: "Marc Snir" From: William Gropp Subject: Re: Handling errors in handle transfer functions Cc: mpi-core@XXXXXXXXXXX,owner-mpi-core@XXXXXXXXXXXXX In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Sender: owner-mpi-core@XXXXXXXXXXXXX Precedence: bulk At 06:17 PM 6/6/2001 -0400, Marc Snir wrote: The behavior that the standard specifies for handle conversion, as was explained by Dick Treumann, is garbage in, same garbage out. A justification for this specification was that, in the case where handles are really one and the same in both languages, then there would be no code in the conversion process. I also think this is the "semantically correct" behavior: the move from one language to another is transparent. Consider, for example, a library written in C, that checks carefully its inputs and generates elaborate error codes and reports. With the current specification, a Fortran interface to the same library does not need to have additional exception handling capabilities: no matter what garbage is passed in, the input will be received and handled correctly inside the C library. I agree with everyone's interpretation of the standard; no change is needed (just for the record, I'm withdrawing my suggestion). However, the request for this came from a library developer that wanted to have some simple way to validate an MPI object in exactly the case that Marc mentions: A library, written in C, gets called by a Fortran routine and is passed what purports to be a valid MPI object (e.g., a communicator), but is in fact invalid (e.g., an uninitialized or misspelled variable). What is missing is an easy way to check for this condition. Note that the first operation that a library may wish to perform is MPI_Comm_dup( MPI_Comm_f2c( f_comm ), &comm ). To properly handle this in MPI now requires: MPI_Comm_get_errhandler( MPI_COMM_WORLD, &errhand ); MPI_Comm_set_errhandler( MPI_COMM_WORLD, MPI_ERRORS_RETURN ); err = MPI_Comm_dup( MPI_Comm_f2c( f_comm ), &lib_comm ); MPI_Comm_set_errhandler( MPI_COMM_WORLD, errhand ); MPI_Errhandler_free( &errhand ); if (err) { ... f_comm was probably invalid ... } MPI_Comm_set_errhandler( lib_comm, MPI_ERRORS_RETURN ); What the library writer really wanted was a "valid" flag on so that the code would be MPI_Comm c_comm = MPI_Comm_f2c( f_comm, &is_valid ); /* not MPI, for illustration only */ if (!is_valid) { ... f_comm was invalid } /* very, very careful routines set/restore errhandler on c_comm, but most do */ MPI_Comm_dup( c_comm, &lib_comm ); MPI_Comm_set_errhandler( lib_comm, MPI_ERRORS_RETURN ); ... As someone has mentioned, having a particular defined value for an invalid handle would have the same effect: MPI_Comm c_comm = MPI_Comm_f2c( f_comm ); if (c_comm == MPI_COMM_INVALID) { /* Not MPI, for illustration only */ ... f_comm was invalid } ... I hope this explains the reason for my note. As Marc notes, the MPI design is semantically sufficient. However, it could be friendlier to library writers. Bill