fortranfortran2018

How to Access a Remote Team in Fortran 2018


I've written a short Fortran program that uses teams, but it doesn't function as expected. I would like to know whether my programming syntax is correct, or if there's a bug in my compiler.

I've been reading a book about Fortran 2018 and some of its newer implementations, including teams. Very few textbooks talk about teams, and the only one I could find, doesn't offer any program examples. I've written, compiled, and run a very short program that is supposed to print a value from one team, while working within another. The syntax seems fairly straight-forward, but the program doesn't work. I've compiled the program using the OpenCoarrays 2.7.1 compiler, as well as version 2.8.0.

program remote_team2
    use iso_fortran_enf
    implicit none

    type(team_type) :: new_team
    integer, codimension[*] :: tempnum

    form team(1+mod(this_image(),2),new_team)

    change team(new_team)
        tempnum = num_images()
        sync team(new_team)

        select case (team_number())
            case(1)
                print *, 1, ' ', tempnum[2], ' ', num_images()
            case(2)
                print *, 2, ' ', tempnum[1], ' ', num_images()
        end select
    end team
end program remote_team2

If I run the program with 5 processors, cafrun -np 5 remote_team2, I would expect something like the following to print out at the screen:

2    3    2
1    2    3
2    3    2
1    2    3
2    3    2

Instead, I get the following:

2    3    3
1    2    2
2    3    3
1    2    2
2    3    3

I don't understand why it's not printing the number of images in the opposite team number, and then printing the number of images in the current team number. Instead, it just prints the same thing twice, indicating that square brace indexing, "[ ]", isn't working.

What am I doing wrong? Are there any Fortran 2018 programmers who may be able to explain this?

Thanks for your time.

Steve Lionel, thanks for the suggestion about looking into the association option with the change team statement. My book mentions this option, but, unfortunately, once again, there are no examples.

Based on the syntax that's described in the book, I have revised my program to look like the following:

program remote_team2
    use iso_fortran_enf
    implicit none

    type(team_type) :: new_team
    integer, codimension[*] :: tempnum
    integer, codimension[2,*] :: tn

    form team(1+mod(this_image(),2),new_team)

    change team(new_team, tempnum[*] => tn)
        tempnum = num_images()
        sync team(new_team)

        select case (team_number())
            case(1)
                print *, 1, ' ', tempnum[1, team_number = 2], ' ', num_images()
            case(2)
                print *, 2, ' ', tempnum[1, team_number = 1], ' ', num_images()
        end select
    end team
end program remote_team2

However, now my compiler gives me a syntax error for my change team statement. The error reads:

change team(new_team, tempnum[*] = > tn)
                   1
Error: Syntax error in CHANGE TEAM statement at (1)

The compiler also gives the following error message:

print *, 1, ' ', tempnum[1, team_number = 2], ' ', num_images()
                                      1
Error: Function 'team_number' requires an argument list at (1)

It seems to think that I'm trying to use team_number as a function, rather than as an indexing option, as described in the book.

Without any published working examples to speak of, not in the book nor online, I don't know what the compiler wants me to do. The book generally shows a "reference book" representation of these definitions. So I'm never quite sure how these statements are actually supposed to look. However, in the case of how I've written both statements, they use the same options that are described in the book. Any suggestions, or ideas, are greatly appreciated.


Solution

  • I've recently learned, from one of the authors of the book I've been reading, that the syntax of my updated program is correct, and can even be simplified. He suggested that my compiler doesn't yet support the feature of accessing information between different teams.

    At least I now know that my syntax is correct.