File: sge_binding_parse.c

package info (click to toggle)
gridengine 8.1.9%2Bdfsg-10
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 56,880 kB
  • sloc: ansic: 432,689; java: 87,068; cpp: 31,958; sh: 29,429; jsp: 7,757; perl: 6,336; xml: 5,828; makefile: 4,701; csh: 3,928; ruby: 2,221; tcl: 1,676; lisp: 669; yacc: 519; python: 503; lex: 361; javascript: 200
file content (183 lines) | stat: -rw-r--r-- 5,827 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*___INFO__MARK_BEGIN__*/

/*************************************************************************
 * 
 *  The Contents of this file are made available subject to the terms of
 *  the Sun Industry Standards Source License Version 1.2
 * 
 *  Sun Microsystems Inc., March, 2001
 * 
 * 
 *  Sun Industry Standards Source License Version 1.2
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.2 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 * 
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 * 
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 * 
 *   Copyright: 2001 by Sun Microsystems, Inc.
 * 
 *   All Rights Reserved.
 * 
 ************************************************************************/

/*___INFO__MARK_END__*/

/* this code is used by shepherd */
#include <ctype.h>
#include <pthread.h>

#include "uti/sge_mtutil.h"
#include "uti/sge_rmon.h"
#include "uti/sge_string.h"
#include "uti/sge_log.h"
#include "uti/sge_binding_parse.h"

binding_type_t binding_type_to_enum(const char* parameter)
{
   binding_type_t type = BINDING_TYPE_NONE;

   if (strstr(parameter, "env") != NULL) {
      type = BINDING_TYPE_ENV;
   } else if (strstr(parameter, "pe") != NULL) {
      type = BINDING_TYPE_PE;
   } else if (strstr(parameter, "set") != NULL) {
      type = BINDING_TYPE_SET;
   }

   return type;
}

bool
binding_type_to_string(binding_type_t type, dstring *string) {
   bool ret = true; 

   if (string != NULL) {
      switch (type) {
         case BINDING_TYPE_SET:
            sge_dstring_append(string, "set");
            break;
         case BINDING_TYPE_PE:
            sge_dstring_append(string, "pe");
            break;           
         case BINDING_TYPE_ENV:
            sge_dstring_append(string, "env");
            break;
         default:
            sge_dstring_append(string, "unknown");
      }
   }
   return ret;
}

bool binding_explicit_extract_sockets_cores(const char* parameter,
   int** list_of_sockets, int* samount, int** list_of_cores, int* camount)
{
   /* string representation of a socket number */
   char* socket = NULL;
   /* string representation of a core number */
   char* core = NULL;
   bool do_endlessly = true;

   /* no sockets and no cores at the beginning */
   *samount = 0;
   *camount = 0;

   if (list_of_sockets == NULL || list_of_cores == NULL || *list_of_sockets != NULL 
         || *list_of_cores != NULL) {
      /* we expect NULL pointers because we allocate memory within the function */
      return false;
   }

   /* check if the prefix of the parameter is correct */
   if (strstr(parameter, "explicit:") == NULL) {
      return false;
   }

   if (sge_strtok(parameter, ":") != NULL) {

      /* first socket,core is mandatory */
      if ((socket = sge_strtok(NULL, ",")) == NULL) {
         /* we have no first socket number */
         return false;
      }
      if ((core = sge_strtok(NULL, ":")) == NULL) {
         /* we have no first core number */
         return false;
      }

      /* adding first socket,core pair */
      *samount = *camount = 1;
      *list_of_sockets = sge_realloc(*list_of_sockets, (*samount)*sizeof(int), 1);
      *list_of_cores = sge_realloc(*list_of_cores, (*camount)*sizeof(int), 1);
      (*list_of_sockets)[0] = atoi(socket);
      (*list_of_cores)[0] = atoi(core);

      while (do_endlessly) {
         /* get socket number */
         if ((socket = sge_strtok(NULL, ",")) == NULL || (isdigit(*socket) == 0)) {
            break;
         }

         /* we have a socket therefore we need a core number */
         if ((core = sge_strtok(NULL, ":")) == NULL || (isdigit(*core) == 0)) {
            /* missing core number */
            sge_free(list_of_sockets);
            sge_free(list_of_cores);
            return false;
         }

         /* adding the next <socket>,<core> tuple */
         (*samount)++; (*camount)++;
         (*list_of_sockets) = sge_realloc(*list_of_sockets, (*samount)*sizeof(int), 1);
         (*list_of_cores) = sge_realloc(*list_of_cores, (*camount)*sizeof(int), 1);
         (*list_of_sockets)[*samount-1] = atoi(socket);
         (*list_of_cores)[*camount-1] = atoi(core);
      }        /* we try to continue with the next socket if possible */
               /* if "S" or "s" is found this is because the binding string 
                  in config file is parsed and the topology used by the job "SccScc" 
                  is followed */

   } else {
      /* this should not be reachable because of the pre-check */
      return false;
   }

   return true;
}

bool 
binding_printf_explicit_sockets_cores(dstring *string, int *socket_array, int sockets, 
                                      int *core_array, int cores) 
{
   bool ret = true;

   if (string != NULL && socket_array != NULL && core_array != NULL && sockets == cores) {
      int i;
      bool first_line = true;

      for (i = 0; i < sockets; i++) {
         if (first_line) {
            sge_dstring_append(string, "explicit:");
            first_line = false;
         } else {
            sge_dstring_append_char(string, ':');
         }
         sge_dstring_sprintf_append(string, "%d,%d", socket_array[i], core_array[i]);
      }
   }

   return ret;
}