1 |
cnh |
1.2 |
C $Header: check_threads.F,v 1.1.1.1 1998/04/22 19:15:30 cnh Exp $ |
2 |
cnh |
1.1 |
|
3 |
|
|
#include "CPP_EEOPTIONS.h" |
4 |
|
|
|
5 |
|
|
CStartOfInterface |
6 |
|
|
SUBROUTINE CHECK_THREADS( myThid ) |
7 |
|
|
C /==========================================================\ |
8 |
|
|
C | SUBROUTINE CHECK_THREADS | |
9 |
|
|
C | o Check that all the threads we need did indeed start. | |
10 |
|
|
C |==========================================================| |
11 |
|
|
C | This routine is called during the initialisation phase | |
12 |
|
|
C | to check whether all the threads have started. | |
13 |
|
|
C | It is invoked by every thread and if any thread finds an | |
14 |
|
|
C | error it should set its error flag. | |
15 |
|
|
C | Notes: | |
16 |
|
|
C | Different mechanisms may be required on different | |
17 |
|
|
C | platforms to actually perform the check. For example as | |
18 |
|
|
C | coded here each thread checks for a semaphore set by the | |
19 |
|
|
C | other threads to see if they are running. | |
20 |
|
|
C | It is also possible for a system to schedule threads | |
21 |
|
|
C | sequentially, unless some system call is made to yield | |
22 |
|
|
C | the process. This routine would detect this situation too| |
23 |
|
|
C | and allow a programmer to modify this routine and the | |
24 |
|
|
C | barrier code to allow threads to be scheduled more | |
25 |
|
|
C | appropriately. | |
26 |
|
|
C \==========================================================/ |
27 |
|
|
|
28 |
|
|
C === Global data === |
29 |
|
|
#include "SIZE.h" |
30 |
|
|
#include "EEPARAMS.h" |
31 |
|
|
#include "EESUPPORT.h" |
32 |
|
|
C === Routine areguments === |
33 |
|
|
C myThid - My thread number |
34 |
|
|
INTEGER myThid |
35 |
|
|
|
36 |
|
|
CEndOfInterface |
37 |
|
|
|
38 |
|
|
C === Local variables === |
39 |
|
|
C I - Loop counter |
40 |
|
|
C numberThreadRunning - Count of number of threads this thread |
41 |
|
|
C thinks are running. |
42 |
|
|
C nChecks - Number of times checked for all threads. After so |
43 |
|
|
C many checks give up and report an error. |
44 |
|
|
INTEGER I |
45 |
|
|
INTEGER numberThreadsRunning |
46 |
|
|
INTEGER nChecks |
47 |
|
|
CHARACTER*(MAX_LEN_MBUF) msgBuffer |
48 |
|
|
C |
49 |
|
|
threadIsRunning(myThid) = .TRUE. |
50 |
|
|
nChecks = 0 |
51 |
|
|
|
52 |
|
|
10 CONTINUE |
53 |
|
|
numberThreadsRunning = 0 |
54 |
|
|
nChecks = nChecks + 1 |
55 |
|
|
DO I = 1, nThreads |
56 |
|
|
IF ( threadIsRunning(I) ) |
57 |
|
|
& numberThreadsRunning = numberThreadsRunning+1 |
58 |
|
|
ENDDO |
59 |
|
|
IF ( nChecks .GT. 10 ) THEN |
60 |
|
|
thError(myThid) = .TRUE. |
61 |
|
|
eeBootError = .TRUE. |
62 |
|
|
WRITE(msgBuffer,'(A,I,A,I,A)') |
63 |
|
|
& 'S/R INI_CHECK_THREADS: Only ',numberThreadsRunning, |
64 |
|
|
& ' thread(s), ',nThreads,' are needed for this configuration!' |
65 |
|
|
CALL PRINT_ERROR( msgBuffer , myThid) |
66 |
|
|
C-- Not enough threads are running so halt the program. |
67 |
|
|
C I didn't want this here but it is the only place I have found that |
68 |
|
|
C KAP deadlocks if it there are fewer threads than iterations in a BLOCKED(1) |
69 |
|
|
C loop. The deadlock appears to be in the routine mppjoin which never |
70 |
|
|
C returns. I tried putting the STOP in main or breaking out of the loop in main |
71 |
|
|
C but this causes KAP to insert a call to mppjoin - which then deadlocks! |
72 |
|
|
IF ( myThid .EQ. 1 ) THEN |
73 |
|
|
STOP 'ABNORMAL END: S/R CHECK_THREADS' |
74 |
|
|
ENDIF |
75 |
|
|
GOTO 11 |
76 |
|
|
ENDIF |
77 |
|
|
IF ( numberThreadsRunning .NE. nThreads ) THEN |
78 |
|
|
CALL SYSTEM('sleep 1') |
79 |
|
|
GOTO 10 |
80 |
|
|
ENDIF |
81 |
|
|
11 CONTINUE |
82 |
|
|
C |
83 |
|
|
C |
84 |
|
|
RETURN |
85 |
|
|
END |