[MPIWG Fortran] New question

Bill Long longb at cray.com
Tue Dec 8 14:45:31 CST 2015


On Dec 8, 2015, at 2:34 PM, Jeff Squyres (jsquyres) <jsquyres at cisco.com> wrote:

> On Dec 8, 2015, at 12:05 PM, Bill Long <longb at cray.com> wrote:
>> 
>>> There's a working group here at the form who is investigating the possibility of passing C function argument as a struct that contains a union, perhaps something like this:
>> 
>> Not a good idea in my opinion.  The whole idea of overlaying memory bits with variables of different types is something that should be limited to low-level system programmers, if even that.    They seem to be wanting to do “fake” polymorphism.    How would they propose that the callee figure out which of the options to choose, without the infrastructure of “real” polymorphism.
> 
> It's a possibility that is being discussed for a generalized MPI err handler (we have 3 different errhandler types right now, and it's actually kinda painful).  :-)
> 
> It may or not go anywhere, but the point is that they asked me: can we do this in Fortran?
> 
>>> struct to_be_passed_as_an_arg {
>>>  enum actual_type;
>>>  union {
>>>     struct {
>>>         MPI_Comm comm;
>>>         // ... several more members
>>>     } comm_stuff;
>>> 
>>>     struct {
>>>         MPI_Win win;
>>>         // ... several more members
>>>     } win_stuff;
>>> 
>>>     struct {
>>>         MPI_File file;
>>>         // ... several more members
>>>     } file_stuff;
>>>  } obj;
>>> };
>>> -----
>>> 
>>> Can we do this in Fortran?  If so, how?
>> 
>> Not really. 
> 
> We're bound to the limitations of C -- so we can't do real polymorphism.  Hence the use of the union.
> 
> Is there any way to do something like this in Fortran?


No. There is no facility for a particular structure component to have more than one type.  And the concept is contrary to the basic Fortran focus on type safety. So I think that adding something like this in the future is very unlikely. 

Cheers,
Bill



> 
>>> Craig suggests that TRANSFER and/or EQUIVALENCE may be helpful here…?
>> 
>> TRANSFER is an executable function.  It would not appear as part of a type declaration.  EQUIVALENCE, apart from being added to  the deprecated list, cannot be applied to component declarations of a type. 
>> 
>> Cheers,
>> Bill
>> 
>> 
>>> 
>>> -- 
>>> Jeff Squyres
>>> jsquyres at cisco.com
>>> For corporate legal information go to: http://www.cisco.com/web/about/doing_business/legal/cri/
>>> 
>>> _______________________________________________
>>> mpiwg-fortran mailing list
>>> mpiwg-fortran at lists.mpi-forum.org
>>> http://lists.mpi-forum.org/mailman/listinfo.cgi/mpiwg-fortran
>> 
>> Bill Long                                                                       longb at cray.com
>> Fortran Technical Support  &                                  voice:  651-605-9024
>> Bioinformatics Software Development                     fax:  651-605-9142
>> Cray Inc./ Cray Plaza, Suite 210/ 380 Jackson St./ St. Paul, MN 55101
>> 
>> 
>> _______________________________________________
>> mpiwg-fortran mailing list
>> mpiwg-fortran at lists.mpi-forum.org
>> http://lists.mpi-forum.org/mailman/listinfo.cgi/mpiwg-fortran
> 
> 
> -- 
> Jeff Squyres
> jsquyres at cisco.com
> For corporate legal information go to: http://www.cisco.com/web/about/doing_business/legal/cri/
> 
> _______________________________________________
> mpiwg-fortran mailing list
> mpiwg-fortran at lists.mpi-forum.org
> http://lists.mpi-forum.org/mailman/listinfo.cgi/mpiwg-fortran

Bill Long                                                                       longb at cray.com
Fortran Technical Support  &                                  voice:  651-605-9024
Bioinformatics Software Development                     fax:  651-605-9142
Cray Inc./ Cray Plaza, Suite 210/ 380 Jackson St./ St. Paul, MN 55101





More information about the mpiwg-fortran mailing list