-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.f90
65 lines (50 loc) · 1.75 KB
/
test.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
program main
use mpi
implicit none
integer :: nprocs, myrank, ierr
integer :: i, j, k, n, tot, nsize=100
integer :: parentcomm, parent_rank, parent_nprocs
character(len=256) :: command_line
integer :: signal
integer :: iargs
character(len=256) :: input_string
character(len=256) :: prefix
call MPI_INIT(ierr)
call MPI_COMM_GET_PARENT(parentcomm, ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD, nprocs, ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD, myrank, ierr)
if (parentcomm == MPI_COMM_NULL) then
prefix='Alone:'
else
prefix='Child:'
endif
iargs = command_argument_count()
if (iargs > 0) then
do i = 1, iargs
call get_command_argument(i, input_string)
print *, trim(prefix), ' Command line arguments: ',trim(input_string)
end do
else
print *, trim(prefix), ' No command line arguments provided.'
input_string = 'None'
end if
write(prefix,'(A6,1X,A7,A1,1X)')trim(prefix),trim(input_string),':'
if (parentcomm == MPI_COMM_NULL) then
print *, trim(prefix), ' Hello from child rank ', myrank, ' of ', nprocs
else
parent_rank = 0
call MPI_COMM_REMOTE_SIZE(parentcomm, parent_nprocs, ierr)
print *, trim(prefix), ' Hello from child rank ', myrank, ' of ', nprocs, ', parent rank ',parent_rank, ' of ', parent_nprocs
call MPI_Barrier(MPI_COMM_WORLD, ierr)
endif
n = myrank + 1
call MPI_REDUCE(n, tot, 1, MPI_INTEGER, MPI_SUM, 0, MPI_COMM_WORLD, ierr)
if (myrank == 0) print *, trim(prefix),' Total = ', tot
if (parentcomm /= MPI_COMM_NULL) then
signal = n
call MPI_Send(signal, 1, MPI_INTEGER, 0, 0, parentcomm, ierr)
call MPI_Barrier(parentcomm, ierr)
endif
!call MPI_Barrier(MPI_COMM_WORLD, ierr)
call MPI_FINALIZE(ierr)
end program main