SURFEX v8.1
General documentation of Surfex
jfh_bind.F90
Go to the documentation of this file.
1  SUBROUTINE jfh_bind()
2 #ifndef RS6K
3  WRITE(0,*) "JFH_BIND compiled without -DRS6K so not binding"
4  RETURN
5  END SUBROUTINE jfh_bind
6 #else
7 ! PURPOSE.
8 ! --------
9 ! Binds task and threads to CPUs for LL submitted jobs
10 ! (not for interactive jobs)
11 
12 ! INTERFACE.
13 ! ----------
14 ! CALL JFH_BIND()
15 
16 ! METHOD.
17 ! -------
18 ! The first call to JFH_BIND routine binds CPUs according to
19 ! the env vars
20 ! JFH_BIND=map
21 ! JFH_BMAP="N 0 1 2 ..." where N is number of entries
22 ! and prints out the binding
23 ! e.g. for 4 threads: CPUs = 0 32 1 33
24 
25 ! Subsequent calls, and calls without env vars set, will not bind,
26 ! but will print out the binding
27 
28 ! JFH_BIND may be called before or after mpi_init
29 
30 ! Note that IFS may also call EC_BIND, which binds differently to
31 ! jfh_bind, but it will not be called (in CY37R3) if:
32 ! mpi_init is called before mpl_init
33 ! the job is not run on whole nodes
34 
35 ! Serial (non MPI) version can be created by compiling with -DSERIAL
36 
37 ! EXTERNALS.
38 ! ----------
39 ! SYSTEM Get host name
40 ! MPI_INITIALIZED Check if mpi iniitalised
41 ! MPI_COMM_RANK Get rank of mpi tasK
42 ! GETENV Get environment variable
43 ! OMP_GET_THREAD_NUM Get thread num
44 ! --- following in jfhc.c-----
45 ! AFF Get cpu num & CPUs per node
46 ! SMTCTL Get CPU ids for SMT id
47 ! IS_SMT_ON Check for SMT
48 ! JBIND Bind thread to processor
49 
50 ! AUTHOR.
51 ! -------
52 ! J.Hague, IBM, Aug 2011
53 ! ------------------------------------------------------------------
54 
55  IMPLICIT NONE
56  INTEGER omp_get_max_threads
57  INTEGER omp_get_thread_num
58  INTEGER, ALLOCATABLE :: ita(:), map(:)
59  INTEGER, ALLOCATABLE :: jcpu(:), id0(:), id1(:)
60  INTEGER ip,it,nt,mp,iproc,nmap
61  INTEGER icpu,ier
62  INTEGER i,ii,mdum
63  INTEGER ismt, is_smt_on
64  INTEGER ifirst, iprt, ira
65  LOGICAL lflg
66  CHARACTER*120 c,c1,c2
67  CHARACTER*3 cb, cc
68  CHARACTER*1000 cbm
69  SAVE cb,cbm
70  DATA ifirst/0/
71 #ifndef SERIAL
72 #ifdef SFX_MPI
73 include "mpif.h"
74 #endif
75 #endif
76 
77  CALL system("hostname")
78 
79 #ifndef SERIAL
80  CALL mpi_initialized(lflg,ier)
81  IF(lflg) THEN
82  CALL mpi_comm_rank(mpi_comm_world,ip,ier)
83  ELSE
84 #ifdef RS6K
85  CALL get_environment_variable("MP_CHILD",VALUE=c)
86 #endif
87  READ(c,*) ip
88  ENDIF
89 !write(0,*) "LFLG,ip=",LFLG,ip
90 #else
91  ip=0
92 #endif
93 
94  CALL aff(mdum,mp)
95  ALLOCATE(map(mp+1))
96  ALLOCATE(jcpu(mp))
97  ALLOCATE(id0(mp/2))
98  ALLOCATE(id1(mp/2))
99  nt=omp_get_max_threads()
100  ALLOCATE(ita(nt))
101 
102  CALL get_environment_variable("JFH_BIND",cb)
103  IF(ifirst.EQ.0) THEN
104  ifirst=1
105  IF(cb.EQ."yes".OR.cb.EQ."YES".OR.cb.EQ."map".OR.cb.EQ."MAP") THEN
106  DO i=1,mp
107  jcpu(i)=i-1
108  ENDDO
109 
110 !---------Must reset jcpu if SMT ON-----------------------------
111  ismt=is_smt_on()
112 ! write(0,*) "ismt=",ismt
113  IF(ismt .NE. -99) THEN
114  CALL smtctl(mp/2, id0, id1)
115  DO i=1,mp/2
116  jcpu(2*i-1)=id0(i)
117  jcpu(2*i )=id1(i)
118  ENDDO
119  ENDIF
120 !---------------------------------------------------------------
121 ! write(0,*) "jcpu=",jcpu
122 
123  map(1)=-1
124  nmap=mp
125  IF(cb.EQ."map".OR.cb.EQ."MAP") THEN
126  CALL get_environment_variable("JFH_BMAP",cbm)
127  READ(cbm,*) nmap,(map(i),i=1,min(mp,nmap))
128 ! write(6,*) "NMAP,Map=",NMAP,(MAP(I),I=1,NMAP)
129  ENDIF
130 
131  ira=0
132  CALL get_environment_variable("JFH_RA_DET",cc)
133  IF(cc.EQ."yes".OR.cc.EQ."YES") ira=1
134 ! write(0,*) "CC,ira=",CC,ira
135  iprt=0
136  CALL get_environment_variable("JFH_RA_PRT",cc)
137  IF(cc.EQ."yes".OR.cc.EQ."YES") iprt=1
138 
139 !$OMP PARALLEL
140  IF(ira==1) THEN
141 ! write(0,*) "Calling ra_det"
142  CALL ra_det(2,iprt)
143  ENDIF
144 !$OMP END PARALLEL
145 
146 !$OMP PARALLEL PRIVATE(IT,IPROC)
147  it=omp_get_thread_num()
148  IF(ira==1) CALL ra_check(2,iprt)
149  iproc=nt*ip+it
150  iproc=mod(iproc,nmap)
151 ! write(0,*) "i,it,IPROC=",i,it,IPROC
152 ! write(0,*) "it,IPROC,MAP,jcpu,MAP",it,IPROC,MAP(IPROC+1),jcpu(MAP(IPROC+1)+1)
153  IF(map(1).EQ.-1) CALL jbind(jcpu(iproc+1))
154  IF(map(1).NE.-1) CALL jbind(jcpu(map(iproc+1)+1))
155 !$OMP END PARALLEL
156 
157  ENDIF
158  ENDIF
159 
160 !$OMP PARALLEL PRIVATE(it,icpu,mdum)
161  it=omp_get_thread_num()
162  CALL aff(icpu,mdum)
163  ita(it+1)=icpu
164 !$OMP END PARALLEL
165  WRITE(0,*) "CPUs = ",(ita(i),i=1,nt)
166  DEALLOCATE(ita,map,jcpu,id0,id1)
167  END SUBROUTINE jfh_bind
168 #endif
int ra_check(const int *check_type, int *prnt)
Definition: ra_check.c:13
int ra_det(int *det_type, int *prnt)
Definition: ra_det.c:13