From owner-sc22wg5+sc22wg5-dom8=www.open-std.org@open-std.org  Wed Aug 31 21:56:47 2011
Return-Path: <owner-sc22wg5+sc22wg5-dom8=www.open-std.org@open-std.org>
X-Original-To: sc22wg5-dom8
Delivered-To: sc22wg5-dom8@www.open-std.org
Received: by www.open-std.org (Postfix, from userid 521)
	id 87E143568CA; Wed, 31 Aug 2011 21:56:47 +0200 (CEST)
Delivered-To: sc22wg5@open-std.org
X-Greylist: delayed 900 seconds by postgrey-1.33 at www5.open-std.org; Wed, 31 Aug 2011 21:56:46 CEST
Received: from mailrelay2.lrz-muenchen.de (mailrelay2.lrz-muenchen.de [129.187.254.102])
	by www.open-std.org (Postfix) with ESMTP id 5D4DA35689B
	for <sc22wg5@open-std.org>; Wed, 31 Aug 2011 21:56:46 +0200 (CEST)
Received: from postout2.mail.lrz.de ([10.156.6.19] [10.156.6.19]) by mailrelay2.lrz-muenchen.de with ESMTP; Wed, 31 Aug 2011 21:41:34 +0200
Received: from BADWLRZ-SWHBT1.ads.mwn.de (BADWLRZ-SWHBT1.ads.mwn.de [IPv6:2001:4ca0:0:108::125])
	(using TLSv1 with cipher AES128-SHA (128/128 bits))
	(No client certificate requested)
	by postout2.mail.lrz.de (Postfix) with ESMTPS id 16C6FA688A;
	Wed, 31 Aug 2011 21:41:33 +0200 (CEST)
Received: from BADWLRZ-SWMBX1.ads.mwn.de ([fe80::11b4:b130:c4e2:2d0e]) by
 BADWLRZ-SWHBT1.ads.mwn.de ([fe80::e42f:e9f5:bde9:f99b%16]) with mapi id
 14.01.0339.001; Wed, 31 Aug 2011 21:41:33 +0200
From: "Bader, Reinhold" <Reinhold.Bader@lrz.de>
To: "j3@j3-fortran.org" <j3@j3-fortran.org>,
    WG5 <sc22wg5@open-std.org>
CC: "Rolf Rabenseifner (rabenseifner@hlrs.de)" <rabenseifner@hlrs.de>
Subject: Callback functions with polymorphic arguments
Thread-Topic: Callback functions with polymorphic arguments
Thread-Index: AcxoE8sdC65HJMNwQ4yfSjNvw0soYg==
Date: Wed, 31 Aug 2011 19:41:33 +0000
Message-Id: <166ED263DF83324D9A3BA67FB6772B2B2663C7EB@BADWLRZ-SWMBX1.ads.mwn.de>
Accept-Language: de-DE, en-US
Content-Language: de-DE
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
x-originating-ip: [129.187.48.232]
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
Sender: owner-sc22wg5@open-std.org
Precedence: bulk

Hello all,=20

consider the following module:

module mod_callback_up_01
  implicit none
  abstract interface
    subroutine callback(data)
      class(*), dimension(:) :: data    ! (A)
    end subroutine
  end interface
contains
  subroutine foo(data, proc)
    class(*), dimension(:) :: data    ! (B)
    procedure(callback) :: proc
    call proc(data)
  end subroutine
end module

and then the following code which uses this module:=20

module mod_impl
  implicit none
  type :: bar
    integer :: i
  end type
contains
  subroutine callback1(data)
    class(bar) :: data(:)         ! (C)
    integer :: i
    do i=3D1,size(data)
      data(i)%i =3D i
    end do
  end subroutine
end module
program prog
  use mod_callback_up_01
  use mod_impl
  integer, parameter :: dim=3D5
  type(bar) :: x(dim)
  call foo(x, callback1)
end program

Questions:

(1) Is the above code standard conforming?

(2) Assume that at (C), the declaration is replaced by=20
       type(bar) :: data(:)
     Is the resulting code standard conforming?
        =20
(3) Assume that at (A) and (B), class(*) is replaced by
     class(base), where base is some known type, and
    bar is an extension of base.
     Is the resulting code standard conforming?

(4) Apply both assumptions in (2) and (3) - is the
     resulting code then standard conforming?

The background for this is the issue of handling callbacks in MPI-3.=20
For backward compatibility it is considered desirable to have=20
abstract interfaces for callbacks which use arguments declared
as TYPE(*), DIMENSION(*). The dummy arguments of the callbacks=20
of course will have some definite type in existing code. (The=20
programmer may still need to add BIND(C), but this is considered=20
sufficiently low-intrusive). Depending on the answers to above questions,=20
something may need to be done about this in the TR.=20

(For the above code, different compilers give widely varying results
with respect  to both compilation and run time behaviour).=20

Regards
Reinhold


