/[MITgcm]/MITgcm/eesupp/src/check_threads.F
ViewVC logotype

Diff of /MITgcm/eesupp/src/check_threads.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.2 by cnh, Thu Apr 23 20:37:29 1998 UTC revision 1.10 by cnh, Fri Sep 21 03:54:34 2001 UTC
# Line 1  Line 1 
1  C $Header$  C $Header$
2    C $Name$
3    
4  #include "CPP_EEOPTIONS.h"  #include "CPP_EEOPTIONS.h"
5    #define HAVE_SYSTEM
6    
7  CStartOfInterface  CBOP
8    C     !ROUTINE: CHECK_THREADS
9    
10    C     !INTERFACE:
11        SUBROUTINE CHECK_THREADS( myThid )        SUBROUTINE CHECK_THREADS( myThid )
12  C     /==========================================================\        IMPLICIT NONE
13  C     | SUBROUTINE CHECK_THREADS                                 |  
14  C     | o Check that all the threads we need did indeed start.   |  C     !DESCRIPTION:
15  C     |==========================================================|  C     *==========================================================
16  C     | This routine is called during the initialisation phase   |  C     | SUBROUTINE CHECK_THREADS                                
17  C     | to check whether all the threads have started.           |  C     | o Check that all the threads we need did indeed start.    
18  C     | It is invoked by every thread and if any thread finds an |  C     *==========================================================
19  C     | error it should set its error flag.                      |  C     | This routine is called during the initialisation phase    
20  C     | Notes:                                                   |  C     | to check whether all the threads have started.            
21  C     |  Different mechanisms may be required on different       |  C     | It is invoked by every thread and if any thread finds an  
22  C     | platforms to actually perform the check. For example as  |  C     | error it should set its error flag.                      
23  C     | coded here each thread checks for a semaphore set by the |  C     | Notes:                                                    
24  C     | other threads to see if they are running.                |  C     |  Different mechanisms may be required on different        
25  C     | It is also possible for a system to schedule threads     |  C     | platforms to actually perform the check. For example as  
26  C     | sequentially, unless some system call is made to yield   |  C     | coded here each thread checks for a semaphore set by the  
27  C     | the process. This routine would detect this situation too|  C     | other threads to see if they are running.                
28  C     | and allow a programmer to modify this routine and the    |  C     | It is also possible for a system to schedule threads      
29  C     | barrier code to allow threads to be scheduled more       |  C     | sequentially, unless some system call is made to yield    
30  C     | appropriately.                                           |  C     | the process. This routine would detect this situation too
31  C     \==========================================================/  C     | and allow a programmer to modify this routine and the    
32    C     | barrier code to allow threads to be scheduled more        
33    C     | appropriately.                                            
34    C     *==========================================================
35    
36  C     === Global data ===  C     !USES:
37    C     == Global variables ==
38  #include "SIZE.h"  #include "SIZE.h"
39  #include "EEPARAMS.h"  #include "EEPARAMS.h"
40  #include "EESUPPORT.h"  #include "EESUPPORT.h"
 C     === Routine areguments ===  
 C     myThid - My thread number  
       INTEGER myThid  
41    
42  CEndOfInterface  C     !INPUT PARAMETERS:
43    C     == Routine arguments ==
44    C     myThid :: My thread number
45          INTEGER myThid
46    
47  C     === Local variables ===  C     !LOCAL VARIABLES:
48  C     I - Loop counter  C     == Local variables ==
49  C     numberThreadRunning - Count of number of threads this thread  C     I :: Loop counter
50  C                           thinks are running.  C     numberThreadRunning :: Count of number of threads this thread
51  C     nChecks - Number of times checked for all threads. After so  C                            thinks are running.
52  C               many checks give up and report an error.  C     nChecks   :: Number of times checked for all threads. After so
53    C                  many checks give up and report an error.
54    C     msgBuffer :: Temp. for preparing text messages.
55        INTEGER I        INTEGER I
56        INTEGER numberThreadsRunning        INTEGER numberThreadsRunning
57        INTEGER nChecks        INTEGER nChecks
58        CHARACTER*(MAX_LEN_MBUF) msgBuffer        CHARACTER*(MAX_LEN_MBUF) msgBuffer
59    CEOP
60    
61  C  C
62        threadIsRunning(myThid) = .TRUE.        threadIsRunning(myThid) = .TRUE.
63        nChecks                 = 0        nChecks                 = 0
# Line 59  C Line 72  C
72        IF ( nChecks .GT. 10 ) THEN        IF ( nChecks .GT. 10 ) THEN
73         thError(myThid) = .TRUE.         thError(myThid) = .TRUE.
74         eeBootError     = .TRUE.         eeBootError     = .TRUE.
75         WRITE(msgBuffer,'(A,I,A,I,A)')         WRITE(msgBuffer,'(A,I5,A,I5,A)')
76       &  'S/R INI_CHECK_THREADS: Only ',numberThreadsRunning,       &  'S/R INI_CHECK_THREADS: Only ',numberThreadsRunning,
77       &  ' thread(s), ',nThreads,' are needed for this configuration!'       &  ' thread(s), ',nThreads,' are needed for this configuration!'
78          CALL PRINT_ERROR( msgBuffer , myThid)          CALL PRINT_ERROR( msgBuffer , myThid)
79  C--     Not enough threads are running so halt the program.  C--     Not enough threads are running so halt the program.
80  C       I didn't want this here but it is the only place I have found that  C       I did not want this here but it is the only place I have found that
81  C       KAP deadlocks if it there are fewer threads than iterations in a BLOCKED(1)  C       KAP deadlocks if it there are fewer threads than iterations in a BLOCKED(1)
82  C       loop. The deadlock appears to be in the routine mppjoin which never  C       loop. The deadlock appears to be in the routine mppjoin which never
83  C       returns. I tried putting the STOP in main or breaking out of the loop in main  C       returns. I tried putting the STOP in main or breaking out of the loop in main
# Line 75  C       but this causes KAP to insert a Line 88  C       but this causes KAP to insert a
88         GOTO 11         GOTO 11
89        ENDIF        ENDIF
90        IF ( numberThreadsRunning .NE. nThreads ) THEN        IF ( numberThreadsRunning .NE. nThreads ) THEN
91    #ifdef HAVE_SYSTEM
92    #ifndef TARGET_T3E
93    #ifndef TARGET_CRAY_VECTOR
94         CALL SYSTEM('sleep 1')         CALL SYSTEM('sleep 1')
95    #endif
96    #endif
97    #endif
98         GOTO 10         GOTO 10
99        ENDIF        ENDIF
100     11 CONTINUE     11 CONTINUE
101  C    
 C  
102        RETURN        RETURN
103        END        END

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.10

  ViewVC Help
Powered by ViewVC 1.1.22