SURFEX v8.1
General documentation of Surfex
stack_overwrite.F90
Go to the documentation of this file.
2 !----------------------------------------------------------------------------------
3 ! This module allows you to check whether an application thread is writing into
4 ! the stack of its neighbouring thread
5 ! To use
6 ! Set N= parthds value in XLSMPOPTS environment variable
7 ! Set NN= to that area of stack which should not be used
8 ! <---thread 1----------> <-----thread 2-------> <---...
9 ! !======|===============|========|==============|====...
10 ! <--NN--> <--NN-->
11 ! <---------N-----------> <---------N---------->
12 ! Add "CALL STACK_OWRITE_SET" in first routine
13 ! Add "CALL STACK_OWRITE_CHK" to any routines called after stack may have been corrupted
14 ! Add "USE STACK_OVERWRITE" to all modified routines
15 ! Compile this routine and all modified routines
16 ! Link and run
17 ! Get "STACK_OWRITE_CHK: nt,ii,zstk=" if stack overwriten
18 !----------------------------------------------------------------------------------
19  USE parkind1 , ONLY : jpim
20  SAVE
21  INTEGER*8 :: stack_owrite_beg(16) ! Change if max threads > 16
22  INTEGER(KIND=JPIM) n,nn
23  parameter(n=25*1000*1000,nn=5*1000*1000)
24 
25  CONTAINS
26  SUBROUTINE stack_owrite_set
27  IMPLICIT NONE
28  INTEGER(KIND=JPIM) N,NN,NT,MT,IER
29  INTEGER(KIND=JPIM) OMP_GET_THREAD_NUM,OMP_GET_MAX_THREADS
30  parameter(n=25*1000*1000)
31  parameter(nn=5*1000*1000)
32 #ifdef SFX_MPI
33  include "mpif.h"
34 #endif
35  INTEGER(KIND=JPIM) ZSTK(n)
36  INTEGER(KIND=JPIM) II,ZOFF,NNN
37  INTEGER*8 ZTMP
38  nt=omp_get_thread_num()
39  mt=omp_get_max_threads()
40  zstk(1:nn)=9999
41  IF(nt>0) THEN
42  ztmp=loc(zstk(1))
43  stack_owrite_beg(nt)=ztmp
44  zoff=(stack_owrite_beg(nt)-ztmp)/4
45 ! write(0,*) "STACK_OWRITE_SET: nt,stack_owrite_beg,loc(zstk(1)),zoff=",nt,stack_owrite_beg(nt),loc(zstk(1)),zoff
46 ! do ii=1,2
47 ! if(zstk(zoff+ii).ne.9999) then
48 ! write(0,*) "STACK_OWRITE_SET: nt,ii,zstk=",nt,ii,zstk(zoff+ii)
49 ! endif
50 ! enddo
51 !-----deliberate overwrite of neighbouring stack---------
52  nnn=n+nn/2
53  WRITE(0,*) "mt,nnn=",mt,nnn
54  IF(nt<mt-1) zstk(nnn)=0
55 !-----------------------------------
56  ENDIF
57  CALL stack_owrite_dum(zstk)
58  END SUBROUTINE stack_owrite_set
59 
60  SUBROUTINE stack_owrite_chk
61  IMPLICIT NONE
62  INTEGER(KIND=JPIM) OMP_GET_THREAD_NUM
63  INTEGER(KIND=JPIM) N,NN,NT,II
64  INTEGER(KIND=JPIM) ZOFF
65  parameter(n=25*1000*1000)
66  parameter(nn=5*1000*1000)
67  INTEGER(KIND=JPIM) ZSTK(n)
68  INTEGER*8 ZTMP
69  nt=omp_get_thread_num()
70  IF(nt>0) THEN
71  ztmp=loc(zstk(1))
72  zoff=(stack_owrite_beg(nt)-ztmp)/4
73 ! write(0,*) "STACK_OWRITE_CHK: nt,owrite_beg,loc(zstk(1)),zoff=",nt,stack_owrite_beg(nt),loc(zstk(1)),zoff
74 ! write(0,*) "STACK_OWRITE_CHK: nt,1,zstk=",nt,1,zstk(zoff+1)
75  DO ii=1,nn
76  IF(zstk(zoff+ii).NE.9999) THEN
77  WRITE(0,*) "STACK_OWRITE_CHK: nt,ii,zstk=",nt,ii,zstk(zoff+ii)
78  ENDIF
79  ENDDO
80 ! write(0,*) "STACK_OWRITE_CHK: nt,NN,zstk=",nt,NN,zstk(zoff+NN)
81  ENDIF
82  END SUBROUTINE stack_owrite_chk
83 
84  SUBROUTINE stack_owrite_dum(IDUM)
85  INTEGER(KIND=JPIM) IDUM(n)
86  END SUBROUTINE stack_owrite_dum
87 
88 END MODULE stack_overwrite
integer, parameter jpim
Definition: parkind1.F90:13
subroutine stack_owrite_set
integer *8, dimension(16) stack_owrite_beg
subroutine stack_owrite_chk
subroutine stack_owrite_dum(IDUM)