|
Packit |
0848f5 |
C -*- Mode: Fortran; -*-
|
|
Packit |
0848f5 |
C
|
|
Packit |
0848f5 |
C (C) 2003 by Argonne National Laboratory.
|
|
Packit |
0848f5 |
C See COPYRIGHT in top-level directory.
|
|
Packit |
0848f5 |
C
|
|
Packit |
0848f5 |
C This is a special test that requires an getarg/iargc routine
|
|
Packit |
0848f5 |
C This tests spawn_mult by using the same executable but different
|
|
Packit |
0848f5 |
C command-line options.
|
|
Packit |
0848f5 |
C
|
|
Packit |
0848f5 |
program main
|
|
Packit |
0848f5 |
C This implicit none is removed here because the iargc was not
|
|
Packit |
0848f5 |
C declared on the old sparc compilers
|
|
Packit |
0848f5 |
C implicit none
|
|
Packit |
0848f5 |
include 'mpif.h'
|
|
Packit |
0848f5 |
integer errs, err
|
|
Packit |
0848f5 |
integer rank, size, rsize, wsize, i
|
|
Packit |
0848f5 |
integer np(2)
|
|
Packit |
0848f5 |
integer infos(2)
|
|
Packit |
0848f5 |
integer errcodes(2)
|
|
Packit |
0848f5 |
integer parentcomm, intercomm
|
|
Packit |
0848f5 |
integer status(MPI_STATUS_SIZE)
|
|
Packit |
0848f5 |
character*(10) inargv(2,6), outargv(2,6)
|
|
Packit |
0848f5 |
character*(30) cmds(2)
|
|
Packit |
0848f5 |
character*(80) argv(64)
|
|
Packit |
0848f5 |
integer argc
|
|
Packit |
0848f5 |
integer ierr
|
|
Packit |
0848f5 |
integer can_spawn
|
|
Packit |
0848f5 |
C
|
|
Packit |
0848f5 |
C Arguments are stored by rows, not columns in the vector.
|
|
Packit |
0848f5 |
C We write the data in a way that looks like the transpose,
|
|
Packit |
0848f5 |
C since Fortran stores by column
|
|
Packit |
0848f5 |
data inargv /"a", "-p", &
|
|
Packit |
0848f5 |
& "b=c", "27", &
|
|
Packit |
0848f5 |
& "d e", "-echo", &
|
|
Packit |
0848f5 |
& "-pf", " ", &
|
|
Packit |
0848f5 |
& "Ss", " ", &
|
|
Packit |
0848f5 |
& " ", " "/
|
|
Packit |
0848f5 |
data outargv /"a", "-p", &
|
|
Packit |
0848f5 |
& "b=c", "27", &
|
|
Packit |
0848f5 |
& "d e", "-echo", &
|
|
Packit |
0848f5 |
& "-pf", " ", &
|
|
Packit |
0848f5 |
& "Ss", " ", &
|
|
Packit |
0848f5 |
& " ", " "/
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
errs = 0
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
call MTest_Init( ierr )
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
call MTestSpawnPossible( can_spawn, errs )
|
|
Packit |
0848f5 |
if ( can_spawn .eq. 0 ) then
|
|
Packit |
0848f5 |
call MTest_Finalize( errs )
|
|
Packit |
0848f5 |
goto 300
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
call MPI_Comm_get_parent( parentcomm, ierr )
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
if (parentcomm .eq. MPI_COMM_NULL) then
|
|
Packit |
0848f5 |
C Create 2 more processes
|
|
Packit |
0848f5 |
cmds(1) = "./spawnmultf"
|
|
Packit |
0848f5 |
cmds(2) = "./spawnmultf"
|
|
Packit |
0848f5 |
np(1) = 1
|
|
Packit |
0848f5 |
np(2) = 1
|
|
Packit |
0848f5 |
infos(1)= MPI_INFO_NULL
|
|
Packit |
0848f5 |
infos(2)= MPI_INFO_NULL
|
|
Packit |
0848f5 |
call MPI_Comm_spawn_multiple( 2, cmds, inargv, &
|
|
Packit |
0848f5 |
& np, infos, 0, &
|
|
Packit |
0848f5 |
& MPI_COMM_WORLD, intercomm, errcodes, ierr )
|
|
Packit |
0848f5 |
else
|
|
Packit |
0848f5 |
intercomm = parentcomm
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
C We now have a valid intercomm
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
call MPI_Comm_remote_size( intercomm, rsize, ierr )
|
|
Packit |
0848f5 |
call MPI_Comm_size( intercomm, size, ierr )
|
|
Packit |
0848f5 |
call MPI_Comm_rank( intercomm, rank, ierr )
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
if (parentcomm .eq. MPI_COMM_NULL) then
|
|
Packit |
0848f5 |
C Master
|
|
Packit |
0848f5 |
if (rsize .ne. np(1) + np(2)) then
|
|
Packit |
0848f5 |
errs = errs + 1
|
|
Packit |
0848f5 |
print *, "Did not create ", np(1)+np(2), &
|
|
Packit |
0848f5 |
& " processes (got ", rsize, ")"
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
do i=0, rsize-1
|
|
Packit |
0848f5 |
call MPI_Send( i, 1, MPI_INTEGER, i, 0, intercomm, ierr )
|
|
Packit |
0848f5 |
enddo
|
|
Packit |
0848f5 |
C We could use intercomm reduce to get the errors from the
|
|
Packit |
0848f5 |
C children, but we'll use a simpler loop to make sure that
|
|
Packit |
0848f5 |
C we get valid data
|
|
Packit |
0848f5 |
do i=0, rsize-1
|
|
Packit |
0848f5 |
call MPI_Recv( err, 1, MPI_INTEGER, i, 1, intercomm, &
|
|
Packit |
0848f5 |
& MPI_STATUS_IGNORE, ierr )
|
|
Packit |
0848f5 |
errs = errs + err
|
|
Packit |
0848f5 |
enddo
|
|
Packit |
0848f5 |
else
|
|
Packit |
0848f5 |
C Child
|
|
Packit |
0848f5 |
C FIXME: This assumes that stdout is handled for the children
|
|
Packit |
0848f5 |
C (the error count will still be reported to the parent)
|
|
Packit |
0848f5 |
argc = iargc()
|
|
Packit |
0848f5 |
do i=1, argc
|
|
Packit |
0848f5 |
call getarg( i, argv(i) )
|
|
Packit |
0848f5 |
enddo
|
|
Packit |
0848f5 |
if (size .ne. 2) then
|
|
Packit |
0848f5 |
errs = errs + 1
|
|
Packit |
0848f5 |
print *, "(Child) Did not create ", 2, &
|
|
Packit |
0848f5 |
& " processes (got ",size, ")"
|
|
Packit |
0848f5 |
call mpi_comm_size( MPI_COMM_WORLD, wsize, ierr )
|
|
Packit |
0848f5 |
if (wsize .eq. 2) then
|
|
Packit |
0848f5 |
errs = errs + 1
|
|
Packit |
0848f5 |
print *, "(Child) world size is 2 but ", &
|
|
Packit |
0848f5 |
& " local intercomm size is not 2"
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
call MPI_Recv( i, 1, MPI_INTEGER, 0, 0, intercomm, status, ierr &
|
|
Packit |
0848f5 |
& )
|
|
Packit |
0848f5 |
if (i .ne. rank) then
|
|
Packit |
0848f5 |
errs = errs + 1
|
|
Packit |
0848f5 |
print *, "Unexpected rank on child ", rank, "(",i,")"
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
C Check the command line
|
|
Packit |
0848f5 |
do i=1, argc
|
|
Packit |
0848f5 |
if (outargv(rank+1,i) .eq. " ") then
|
|
Packit |
0848f5 |
errs = errs + 1
|
|
Packit |
0848f5 |
print *, "Wrong number of arguments (", argc, ")"
|
|
Packit |
0848f5 |
goto 200
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
if (argv(i) .ne. outargv(rank+1,i)) then
|
|
Packit |
0848f5 |
errs = errs + 1
|
|
Packit |
0848f5 |
print *, "Found arg ", argv(i), " but expected ", &
|
|
Packit |
0848f5 |
& outargv(rank+1,i)
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
enddo
|
|
Packit |
0848f5 |
200 continue
|
|
Packit |
0848f5 |
if (outargv(rank+1,i) .ne. " ") then
|
|
Packit |
0848f5 |
C We had too few args in the spawned command
|
|
Packit |
0848f5 |
errs = errs + 1
|
|
Packit |
0848f5 |
print *, "Too few arguments to spawned command"
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
C Send the errs back to the master process
|
|
Packit |
0848f5 |
call MPI_Ssend( errs, 1, MPI_INTEGER, 0, 1, intercomm, ierr )
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
C It isn't necessary to free the intercomm, but it should not hurt
|
|
Packit |
0848f5 |
call MPI_Comm_free( intercomm, ierr )
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
C Note that the MTest_Finalize get errs only over COMM_WORLD
|
|
Packit |
0848f5 |
if (parentcomm .eq. MPI_COMM_NULL) then
|
|
Packit |
0848f5 |
call MTest_Finalize( errs )
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
300 continue
|
|
Packit |
0848f5 |
call MPI_Finalize( ierr )
|
|
Packit |
0848f5 |
end
|