setup_mpi.f
2.07 KB
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
c---------------------------------------------------------------------
c---------------------------------------------------------------------
subroutine setup_mpi
c---------------------------------------------------------------------
c---------------------------------------------------------------------
c---------------------------------------------------------------------
c set up MPI stuff
c---------------------------------------------------------------------
implicit none
include 'mpinpb.h'
include 'npbparams.h'
integer error, color, nc
call mpi_init(error)
call mpi_comm_size(MPI_COMM_WORLD, total_nodes, error)
call mpi_comm_rank(MPI_COMM_WORLD, node, error)
if (.not. convertdouble) then
dp_type = MPI_DOUBLE_PRECISION
else
dp_type = MPI_REAL
endif
c---------------------------------------------------------------------
c compute square root; add small number to allow for roundoff
c---------------------------------------------------------------------
nc = dint(dsqrt(dble(total_nodes) + 0.00001d0))
c---------------------------------------------------------------------
c We handle a non-square number of nodes by making the excess nodes
c inactive. However, we can never handle more cells than were compiled
c in.
c---------------------------------------------------------------------
if (nc .gt. maxcells) nc = maxcells
if (node .ge. nc*nc) then
active = .false.
color = 1
else
active = .true.
color = 0
end if
call mpi_comm_split(MPI_COMM_WORLD,color,node,comm_setup,error)
if (.not. active) return
call mpi_comm_size(comm_setup, no_nodes, error)
call mpi_comm_dup(comm_setup, comm_solve, error)
call mpi_comm_dup(comm_setup, comm_rhs, error)
c---------------------------------------------------------------------
c let node 0 be the root for the group (there is only one)
c---------------------------------------------------------------------
root = 0
return
end