SURFEX v8.1
General documentation of Surfex
ra_det.c
Go to the documentation of this file.
1 #if defined RS6K
2 #include <sys/rset.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <sys/thread.h>
7 
8 #define CHECK_PROC 1
9 #define CHECK_THREAD 2
10 #define ra_det ra_det_
11 
12 /*------ Code supplied by Will Weir------------*/
13 int ra_det(int *det_type, int *prnt)
14 {
15  int rs,preDetachrs,postDetachrs;
16  int thread_num;
17  rstype_t rstype;
18  rsid_t rsid;
19  rsethandle_t rset;
20  char *preRSET;
21  char *postRSET;
22  char *tid_string;
23 /* preRSET=malloc(25*sizeof(char));
24  postRSET=malloc(25*sizeof(char)); */
25  tid_string=malloc(4*sizeof(char));
26 
27  pid_t mypid;
28  tid_t mytid;
29 
30  mypid=getpid();
31  mytid=thread_self();
32 
33  rset=rs_alloc(RS_EMPTY);
34 
35  if ( *det_type==CHECK_PROC ) {
36  rstype=R_PROCESS;
37  rsid.at_pid=RS_MYSELF;
38  sprintf(tid_string," %d",mypid);
39  }
40  else if ( *det_type==CHECK_THREAD ) {
41  rstype=R_THREAD;
42  rsid.at_tid=RS_MYSELF;
43  thread_num=omp_get_thread_num();
44  sprintf(tid_string," %d: %d",thread_num,mytid);
45  }
46  else {
47  fprintf(stderr,"Error: rstype not R_PROCESS (1) or R_THREAD (2)\n");
48 /* exit(-1); */
49  }
50 
51 /* Check current association */
52  preDetachrs=ra_getrset(rstype,rsid,0,rset);
53 
54  switch (preDetachrs) {
55  case RS_EFFECTIVE_RSET:
56  preRSET="RS_EFFECTIVE_RSET";
57  break;
58  case RS_PARTITION_RSET:
59  preRSET="RS_PARTITION_RSET";
60  break;
61  case RS_DEFAULT_RSET:
62  preRSET="RS_DEFAULT_RSET";
63  break;
64  case RS_THREAD_RSET:
65  preRSET="RS_THREAD_RSET";
66  break;
67  case RS_THREAD_PARTITION_RSET:
68  preRSET="RS_THREAD_PARTITION_RSET";
69  break;
70 /*----does not work on P6----------
71  case RS_ADVISORY_RSET:
72  preRSET="RS_ADVISORY_RSET";
73  break;
74 */
75  }
76 
77  rs=ra_detachrset(rstype,rsid,0);
78 
79  postDetachrs=ra_getrset(rstype,rsid,0,rset);
80 
81  switch (postDetachrs) {
82  case RS_EFFECTIVE_RSET:
83  postRSET="RS_EFFECTIVE_RSET";
84  break;
85  case RS_PARTITION_RSET:
86  postRSET="RS_PARTITION_RSET";
87  break;
88  case RS_DEFAULT_RSET:
89  postRSET="RS_DEFAULT_RSET";
90  break;
91  case RS_THREAD_RSET:
92  postRSET="RS_THREAD_RSET";
93  break;
94  case RS_THREAD_PARTITION_RSET:
95  postRSET="RS_THREAD_PARTITION_RSET";
96  break;
97 /*----does not work on P6----------
98  case RS_ADVISORY_RSET:
99  postRSET="RS_ADVISORY_RSET";
100  break;
101 */
102  }
103 
104 
105  if ( rs!=0 ) {
106  perror("ra_detachrset error:");
107 /* exit(-1); */
108  } else {
109  if(*prnt==1) fprintf(stderr,"ra_det:%s Successfully detached from rset: %s. Current rset: %s\n",tid_string,preRSET,postRSET);
110  }
111 }
112 #endif
int ra_det(int *det_type, int *prnt)
Definition: ra_det.c:13