On Fri, Aug 19, 2016 at 2:55 PM, Jeff Squyres (jsquyres) <jsquy...@cisco.com > wrote:
> On Aug 19, 2016, at 2:30 PM, Matt Thompson <fort...@gmail.com> wrote: > > > > I'm slowly trying to learn and transition to 'use mpi_f08'. So, I'm > writing various things and I noticed that this triggers an error: > > > > program hello_world > > use mpi_f08 > > implicit none > > type(MPI_Comm) :: comm = MPI_COMM_NULL > > end program hello_world > > > > when compiled (Open MPI 2.0.0 with GCC 6.1): > > > > (380) $ mpifort test1.F90 > > test1.F90:7:27: > > > > type(MPI_Comm) :: comm = MPI_COMM_NULL > > 1 > > Error: Parameter ‘mpi_comm_null’ at (1) has not been declared or is a > variable, which does not reduce to a constant expression > > > > Why is that? Obviously, I can just do: > > > > type(MPI_Comm) :: comm > > comm = MPI_COMM_NULL > > > > and that works just fine (note MPI_COMM_NULL doesn't seem to be special > as MPI_COMM_WORLD triggers the same error). > > I am *not* a Fortran expert, but I believe the difference between the two > is: > > 1. The first one is a compile-time assignment. And you can only do those > with constants. MPI_COMM_NULL is not a compile-time constant, hence, you > get an error. > > 2. The second one is a run-time assignment. You can do that between any > compatible entities, and so that works. > Okay. This makes sense. I guess I was surprised that MPI_COMM_NULL wasn't a constant (or parameter, I guess). But maybe a type() cannot be constant... > > > I'm just wondering why the first doesn't work, for my own edification. I > tried reading through the Standard, but my eyes started watering after a > bit (though that might have been the neon green cover). Is it related to > the fact that when one declares: > > > > type(MPI_Comm) :: comm > > > > that the comm == MPI_COMM_WORLD evaluates to .TRUE.? I discovered that > once when I was printing some stuff. > > That might well be a coincidence. type(MPI_Comm) is not a boolean type, > so I'm not sure how you compared it to .true. Well, I made a program like: (208) $ cat test2.F90 program whoami use mpi_f08 implicit none type(MPI_Comm) :: comm if (comm == MPI_COMM_WORLD) write (*,*) "I am MPI_COMM_WORLD" if (comm == MPI_COMM_NULL) write (*,*) "I am MPI_COMM_NULL" end program whoami (209) $ mpifort test2.F90 (210) $ mpirun -np 4 ./a.out I am MPI_COMM_WORLD I am MPI_COMM_WORLD I am MPI_COMM_WORLD I am MPI_COMM_WORLD I think if you print comm, you get 0 and MPI_COMM_WORLD=0 and MPI_COMM_NULL=2 so...I guess I'm surprised. I'd have thought MPI_Comm would have been undefined until defined. Instead you can write a program like this: (226) $ cat helloWorld.mpi3.F90 program hello_world use mpi_f08 implicit none type(MPI_Comm) :: comm integer :: myid, npes, ierror integer :: name_length character(len=MPI_MAX_PROCESSOR_NAME) :: processor_name call mpi_init(ierror) call MPI_Comm_Rank(comm,myid,ierror) write (*,*) 'ierror: ', ierror call MPI_Comm_Size(comm,npes,ierror) call MPI_Get_Processor_Name(processor_name,name_length,ierror) write (*,'(A,X,I4,X,A,X,I4,X,A,X,A)') "Process", myid, "of", npes, "is on", trim(processor_name) call MPI_Finalize(ierror) end program hello_world (227) $ mpifort helloWorld.mpi3.F90 (228) $ mpirun -np 4 ./a.out ierror: 0 ierror: 0 ierror: 0 ierror: 0 Process 2 of 4 is on compy Process 1 of 4 is on compy Process 3 of 4 is on compy Process 0 of 4 is on compy This seems odd to me. I haven't passed in MPI_COMM_WORLD as the communicator to MPI_Comm_Rank, and yet, it worked and the error code was 0 (which I'd take as success). Even if you couldn't detect this at compile time, I'm surprised it doesn't trigger a run-time error. Is this the correct behavior according to the Standard? Matt -- Matt Thompson
_______________________________________________ users mailing list users@lists.open-mpi.org https://rfd.newmexicoconsortium.org/mailman/listinfo/users