Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Issue with string coarrays

OP1
New Contributor III
1,630 Views

The following program outputs some garbage in the string S (after the concatenated part), is this expected?

PROGRAM P
IMPLICIT NONE
INTEGER :: I
CHARACTER(LEN=20) :: S
  • S = '' SYNC ALL IF (THIS_IMAGE()==1) THEN S = 'A' DO I=1,NUM_IMAGES() S = TRIM(S) // 'B' END DO END IF SYNC ALL WRITE(*,*) S END PROGRAM P
  •  

    0 Kudos
    5 Replies
    Steven_L_Intel1
    Employee
    1,630 Views

    Not expected by me, at least. We'll take a look.

    0 Kudos
    Michael_S_17
    New Contributor I
    1,630 Views

    Which compiler do you use? I remember such problems with ifort 14 when using character components of derived type coarrays.  But since ifort 15 everything works fine in my own programming.

    regards Michael

    0 Kudos
    OP1
    New Contributor III
    1,630 Views

    Michael, this is with IVF 16.0 Update 1.

    0 Kudos
    Steven_L_Intel1
    Employee
    1,630 Views

    Escalated as issue DPD200380661. It seems to have something to do with the TRIM(S) in the expression, though printing TRIM(S) by itself is ok.

    By the way, we've made some changes in the way the forums display member names, and if you haven't set a "Display Name", or your display name is the same as your login ID, it will now show as "(Name Withheld)". If you want to fix this, click on the arrow to the right of your name at the upper right, select Dashboard, and then edit your profile.

    0 Kudos
    Michael_S_17
    New Contributor I
    1,630 Views

    I just tried your code with both, ifort 15 and gfortran 6/OpenCoarrays 1.0.1. Indeed, your code does puzzle both coarray implementations. I did slightly modify your code to figure out what the reason could be. The following code does work with both compilers (BTW, since you start the DO loop counter with 1 you get AB on image 1 and ABB on all other images for S):

    PROGRAM P
    IMPLICIT NONE
    INTEGER :: I
    CHARACTER(LEN=20) :: S


  • CHARACTER(LEN=20) :: T
    S = ''
    SYNC ALL
    IF (THIS_IMAGE()==1) THEN
      S = 'A'
      DO I=1,NUM_IMAGES()
        T = TRIM(S) // 'B'
        S = T
      END DO
    END IF
    SYNC ALL
    WRITE(*,*) S
    END PROGRAM P
  • Maybe this could be an example that both coarray implementations can't efficiently compile the remote data references due to the concatenation operator.

    Isn't that also an issue of coarray correspondence as described by chapter 2 of Aleksandar Donev's 'Rationale for Co-Arrays in Fortran 2008' paper? As far as my understanding goes, in its extreme form, coarray correspondence would impose a syntax for remote data transfer like this: S=S. Of course, our coarray implementations (ifort and gfortran/OpenCoarrays) can already handle remote data references even if we use a purely local object (T in the code change I made) or even with numerical operations on the right-handed side of an assignment for example. (But possibly not with a character concatenation operation as shown in the original code). The essential statement from Aleksandar Donev's paper could be: "This correspondence is essential for both the semantics, in the sense that it enables the programmer to reason about what object a co-indexed data reference really refers to, and for implementations, since it enables efficient compilation of remote data references."

    Of course, these are only my current personal thoughts.

    Best Regards Michael

    0 Kudos
    Reply