stop.F90 7.54 KB
Newer Older
1
2
3
4
5
6
!--------------------------------------------------------------------------------
! Copyright (c) 2016 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
! This file is part of FLEUR and available as free software under the conditions
! of the MIT license as expressed in the LICENSE file in more detail.
!--------------------------------------------------------------------------------

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
MODULE m_juDFT_stop
  !-----------------------------------------------
  !    module to terminate Calculation, should be used instead
  !    of a simple STOP
  !
  !    error(message,calledby,hint,no,warning)
  !         message  : message string
  !         calledby : subroutine in which error occurs(optional)
  !         hint     : string with more information (optional)
  !         no       : error number (optional)
  !         warning  : logical indicating a warning message (optional)
  !
  !    warn(message,calledby,hint,no)
  !         shortcut for calling error with warning=.true.
  !
  !    juDFT_end(message)
  !         call this to terminate without error
  !
  !   IF the file "JUDFT_WARN_ONLY" is not present, warnings will lead to errors.
  !
  !   If the file "JUDFT_TRACE" is present, a stacktrace will be generated
  !   on some compilers
  !
  !
  !                 Daniel Wortmann (2010)
  !-----------------------------------------------
  USE m_judft_time
  USE m_judft_sysinfo
35
  USE m_judft_args
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  IMPLICIT NONE
  PRIVATE
  PUBLIC juDFT_error,juDFT_warn,juDFT_end,judft_file_readable
CONTAINS

  SUBROUTINE judfT_file_readable(filename,warning)
    IMPLICIT NONE
    CHARACTER(len=*),INTENT(IN):: filename
    LOGICAL,INTENT(IN),OPTIONAL:: warning
    LOGICAL  :: l_exist

    INQUIRE(file=filename,exist=l_exist)
    IF (.not.l_exist) CALL judft_error("File not readable:"//filename,hint="FLEUR wants to read a file that is not present",warning=warning)
  END SUBROUTINE judfT_file_readable

  SUBROUTINE juDFT_error(message,calledby,hint,no,warning,file,line)
52
    USE m_judft_usage
53
54
55
56
57
58
59
60
61
62
63
64
65
    IMPLICIT NONE
    CHARACTER*(*),INTENT(IN)          :: message
    CHARACTER*(*),OPTIONAL,INTENT(IN) :: calledby,hint
    INTEGER,OPTIONAL,INTENT(IN)       :: no
    LOGICAL,OPTIONAL,INTENT(IN)       :: warning
    CHARACTER*(*),OPTIONAL,INTENT(IN) :: file
    INTEGER,INTENT(IN),OPTIONAL       :: line

    LOGICAL :: callstop,warn
    CHARACTER(LEN=4)::PE
    !store all output in variable for single call to write in MPI case
    CHARACTER(len=300)::text(10)
    INTEGER           ::linenr,n
66
#ifdef CPP_MPI
67
68
69
70
    include 'mpif.h'
    INTEGER :: irank,e
    CALL MPI_COMM_RANK(MPI_COMM_WORLD,irank,e)
    WRITE(PE,"(i4)") irank
71
#else
72
    PE=" ****"
73
#endif
74
75
76
77
    warn = .FALSE.
    IF (PRESENT(warning)) warn = warning
    IF (warn) THEN
       !check if we stop nevertheless
78
79
80
81
82
83
84
       IF (judft_was_argument("-warn_only")) THEN
          callstop=.false.
       ELSE
          INQUIRE(FILE ="JUDFT_WARN_ONLY",EXIST= callstop)

          callstop  = .NOT.callstop
       ENDIF
85
86
87
    ELSE
       callstop = .TRUE.
    ENDIF
88
    
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
    IF (.NOT.warn) THEN
       WRITE(text(1),*) PE,"**************juDFT-Error*****************"
    ELSE
       WRITE(text(1),*) PE,"************juDFT-Warning*****************"
    ENDIF
    WRITE(text(2),"(3a)") PE,"Error message:",message
    linenr=3
    IF (PRESENT(calledby)) THEN
       WRITE(text(3),"(3a)") PE,"Error occurred in subroutine:",calledby
       linenr=4
    ENDIF
    IF (PRESENT(hint)) THEN
       WRITE(text(linenr),"(3a)") PE,"Hint:",hint
       linenr=linenr+1
    ENDIF
    IF (PRESENT(no)) THEN
       WRITE(text(linenr),"(2a,i0)") PE,"Error number:",no
       linenr=linenr+1
    ENDIF
    IF (present(file)) THEN
       if (present(line)) THEN
          write(text(linenr),"(4a,i0)") PE,"Source:",file,":",line
       ELSE
          write(text(linenr),"(3a)") PE,"Source:",file
       ENDIF
       linenr=linenr+1
    ENDIF
    WRITE(text(linenr),*) PE,"*****************************************"

    if (.not.warn) CALL juDFT_time_lastlocation(PE)

    IF (callstop) THEN
       IF (warn) THEN
122
          linenr=linenr+1
123
124
          WRITE(text(linenr),'(a)')"Warnings not ignored. Touch 'JUDFT_WARN_ONLY' to make the warning nonfatal"
       ENDIF
125
126
       WRITE(0,*)
       WRITE(0,"(10(a,/))") (TRIM(text(n)),n=1,linenr)
127
128
129
130

       CALL add_usage_data("Error",message)
       CALL send_usage_data()
       
131
132
       CALL juDFT_STOP()
    ENDIF
133
    WRITE(0,*)
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
    write(0,"(10(a,/))") (trim(text(n)),n=1,linenr)
  END SUBROUTINE juDFT_error

  SUBROUTINE juDFT_warn(message,calledby,hint,no,file,line)
    IMPLICIT NONE
    CHARACTER*(*),INTENT(IN)          :: message
    CHARACTER*(*),OPTIONAL,INTENT(IN) :: calledby,hint
    INTEGER,OPTIONAL,INTENT(IN)       :: no
    CHARACTER*(*),OPTIONAL,INTENT(IN) :: file
    INTEGER,INTENT(IN),OPTIONAL       :: line

    CALL juDFT_error(message,calledby,hint,no,warning = .TRUE.,file=file,line=line)

  END SUBROUTINE juDFT_warn

  SUBROUTINE juDFT_END(message, irank, l_endXML)
    ! If irank is present every mpi process has to call this routine.
    ! Otherwise only a single mpi process is allowed to call the routine.
    USE m_xmlOutput
153
    USE m_judft_usage
154
    IMPLICIT NONE
155
#ifdef CPP_MPI
156
157
    INCLUDE 'mpif.h'
    INTEGER :: ierr
158
#endif
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
    CHARACTER*(*), INTENT(IN)      :: message
    INTEGER, OPTIONAL, INTENT(IN)  :: irank
    LOGICAL, OPTIONAL, INTENT(IN)  :: l_endXML

    LOGICAL l_endXML_local

    l_endXML_local = .TRUE.
    IF(PRESENT(l_endXML)) THEN
       l_endXML_local = l_endXML
    END IF

    IF(l_endXML_local) THEN
       IF(PRESENT(irank)) THEN
          IF (irank.EQ.0) CALL endXMLOutput()
       ELSE
          ! It is assumed that this is the only mpi process calling this routine.
          CALL endXMLOutput()
       END IF
    END IF
178
    WRITE(0,*)
179
180
181
182
183
184
185
    WRITE(0,*) "*****************************************"
    WRITE(0,*) "Run finished successfully"
    WRITE(0,*) "Stop message:"
    WRITE(0,*) "  ",message
    WRITE(0,*) "*****************************************"
    CALL writetimes()
    CALL print_memory_info()
186
    CALL send_usage_data()
187
#ifdef CPP_MPI
188
189
190
191
192
193
    IF(PRESENT(irank)) THEN
       CALL MPI_BARRIER(MPI_COMM_WORLD,ierr)
       CALL MPI_FINALIZE(ierr)
    ELSE
       CALL juDFT_STOP(0)
    END IF
194
#endif
195
196
    STOP 'OK'
  END SUBROUTINE juDFT_END
197

198
199
200
  !this is a private subroutine that stops the calculations
  !different compilers might have to be added here
  SUBROUTINE juDFT_stop(errorCode)
201
#ifdef __INTEL_COMPILER
202
    USE ifcore
203
204
#endif
#ifdef CPP_MPI
205
    INCLUDE 'mpif.h'
206
#endif
207
208
209
210
    INTEGER, OPTIONAL, INTENT(IN)  :: errorCode
    INTEGER :: error
    LOGICAL :: calltrace
    LOGICAL,ALLOCATABLE:: a(:)
211
#ifdef CPP_MPI
212
    INTEGER :: ierr
213
#endif
214
215
216
217
218
219
220
221
222
223
    error = 0

    IF(PRESENT(errorCode)) THEN
       error = errorCode
    END IF
    !try to print times
    call writelocation()
    CALL writetimes(.TRUE.)
    CALL print_memory_info()
    INQUIRE(FILE="JUDFT_TRACE",EXIST=calltrace)
224
    IF (judft_was_argument("-trace")) calltrace=.TRUE.
225
226
    IF (error.EQ.1) calltrace = .TRUE.
    IF (calltrace) THEN
227
#ifdef __INTEL_COMPILER
228
       CALL tracebackqq(USER_EXIT_CODE=-1) !return after traceback
229
#elif (defined(CPP_AIX)&&!defined(__PGI))
230
       CALL xl__trbk()
231
#endif
232
233
       DEALLOCATE(a)!will generate an error that can be found by the compiler
    ENDIF
234
235

#if defined(CPP_MPI)
236
237
238
239
240
241
242
243
    IF(error.EQ.0) THEN
       WRITE(0,*) ""
       WRITE(0,*) "Terminating all MPI processes."
       WRITE(0,*) "Note: This is a normal procedure."
       WRITE(0,*) "      Error messages in the following lines can be ignored."
       WRITE(0,*) ""
    END IF
    CALL MPI_ABORT(MPI_COMM_WORLD,error,ierr)
244
#endif
245
246
    STOP 'juDFT-STOPPED'
  END SUBROUTINE juDFT_stop
247
248


249
END MODULE m_juDFT_stop
250
251