openmp_runtime_support_environment.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2014 INRIA
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <starpu.h>
  17. #ifdef STARPU_OPENMP
  18. #include <util/openmp_runtime_support.h>
  19. #include <stdlib.h>
  20. #include <ctype.h>
  21. #include <strings.h>
  22. #define _STARPU_INITIAL_PLACES_LIST_SIZE 4
  23. #define _STARPU_INITIAL_PLACE_ITEMS_LIST_SIZE 4
  24. #define _STARPU_DEFAULT_STACKSIZE 2097152
  25. static struct starpu_omp_initial_icv_values _initial_icv_values =
  26. {
  27. .dyn_var = 0,
  28. .nest_var = 0,
  29. .nthreads_var = NULL,
  30. .run_sched_var = starpu_omp_sched_static,
  31. .run_sched_chunk_var = 0,
  32. .def_sched_var = starpu_omp_sched_static,
  33. .def_sched_chunk_var = 0,
  34. .bind_var = NULL,
  35. .stacksize_var = _STARPU_DEFAULT_STACKSIZE,
  36. .wait_policy_var = 0,
  37. .max_active_levels_var = STARPU_OMP_MAX_ACTIVE_LEVELS,
  38. .active_levels_var = 0,
  39. .levels_var = 0,
  40. .place_partition_var = 0,
  41. .cancel_var = 0,
  42. .default_device_var = 0,
  43. .max_task_priority_var = 0
  44. };
  45. struct starpu_omp_initial_icv_values *_starpu_omp_initial_icv_values = NULL;
  46. /* TODO: move to utils */
  47. static void remove_spaces(char *str)
  48. {
  49. int i = 0;
  50. int j = 0;
  51. while (str[j] != '\0')
  52. {
  53. if (isspace(str[j]))
  54. {
  55. j++;
  56. continue;
  57. }
  58. if (j > i)
  59. {
  60. str[i] = str[j];
  61. }
  62. i++;
  63. j++;
  64. }
  65. if (j > i)
  66. {
  67. str[i] = str[j];
  68. }
  69. }
  70. /* TODO: move to utils */
  71. static int strings_cmp(const char *strings[], const char *str)
  72. {
  73. int mode = 0;
  74. while (strings[mode])
  75. {
  76. if (strncasecmp(str, strings[mode], strlen(strings[mode])) == 0)
  77. break;
  78. mode++;
  79. }
  80. if (strings[mode] == NULL)
  81. return -1;
  82. return mode;
  83. }
  84. /* TODO: move to utils */
  85. static int stringsn_cmp(const char *strings[], const char *str, size_t n)
  86. {
  87. int mode = 0;
  88. while (strings[mode])
  89. {
  90. if (strncasecmp(str, strings[mode], n) == 0)
  91. break;
  92. mode++;
  93. }
  94. if (strings[mode] == NULL)
  95. return -1;
  96. return mode;
  97. }
  98. /* TODO: move to utils */
  99. static int read_string_var(const char *str, const char *strings[], int *dst)
  100. {
  101. int val;
  102. if (!str)
  103. return 0;
  104. val = strings_cmp(strings, str);
  105. if (val < 0)
  106. return 0;
  107. *dst = val;
  108. return 1;
  109. }
  110. /* TODO: move to utils */
  111. static int read_int_var(const char *str, int *dst)
  112. {
  113. char *endptr;
  114. int val;
  115. if (!str)
  116. return 0;
  117. errno = 0; /* To distinguish success/failure after call */
  118. val = (int)strtol(str, &endptr, 10);
  119. /* Check for various possible errors */
  120. if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) || (errno != 0 && val == 0))
  121. return 0;
  122. /* No digits were found. */
  123. if (str == endptr)
  124. return 0;
  125. *dst = val;
  126. return 1;
  127. }
  128. static void read_size_var(const char *var, int *dest)
  129. {
  130. const char *env = starpu_getenv(var);
  131. if (env)
  132. {
  133. char *str = strdup(env);
  134. if (str == NULL)
  135. _STARPU_ERROR("memory allocation failed\n");
  136. remove_spaces(str);
  137. if (str[0] == '\0')
  138. {
  139. free(str);
  140. return;
  141. }
  142. char *endptr = NULL;
  143. int mult = 1024;
  144. errno = 0;
  145. int v = (int)strtol(str, &endptr, 10);
  146. if (errno != 0)
  147. _STARPU_ERROR("could not parse environment variable %s, strtol failed with error %s\n", var, strerror(errno));
  148. if (*endptr != '\0')
  149. {
  150. switch (*endptr)
  151. {
  152. case 'b':
  153. case 'B': mult = 1; break;
  154. case 'k':
  155. case 'K': mult = 1024; break;
  156. case 'm':
  157. case 'M': mult = 1024*1024; break;
  158. case 'g':
  159. case 'G': mult = 1024*1024*1024; break;
  160. default:
  161. _STARPU_ERROR("could not parse environment variable %s size suffix invalid\n", var);
  162. }
  163. }
  164. *dest = v*mult;
  165. free(str);
  166. }
  167. }
  168. static void read_sched_var(const char *var, int *dest, unsigned long long *dest_chunk)
  169. {
  170. const char *env = starpu_getenv(var);
  171. if (env)
  172. {
  173. char *str = strdup(env);
  174. if (str == NULL)
  175. _STARPU_ERROR("memory allocation failed\n");
  176. remove_spaces(str);
  177. if (str[0] == '\0')
  178. {
  179. free(str);
  180. return;
  181. }
  182. static const char *strings[] = { "undefined", "static", "dynamic", "guided", "auto", NULL };
  183. int mode = strings_cmp(strings, str);
  184. if (mode < 0)
  185. _STARPU_ERROR("parse error in variable %s\n", var);
  186. *dest = mode;
  187. int offset = strlen(strings[mode]);
  188. if (str[offset] == ',')
  189. {
  190. offset++;
  191. errno = 0;
  192. long long v = strtoll(str+offset, NULL, 10);
  193. if (errno != 0)
  194. _STARPU_ERROR("could not parse environment variable %s, strtol failed with error %s\n", var, strerror(errno));
  195. if (v < 0)
  196. _STARPU_ERROR("invalid negative modifier in environment variable %s\n", var);
  197. unsigned long long uv = (unsigned long long) v;
  198. *dest_chunk = uv;
  199. }
  200. else
  201. {
  202. *dest_chunk = 1;
  203. }
  204. free(str);
  205. }
  206. }
  207. static void read_wait_policy_var()
  208. {
  209. const char *strings[] = { "passive", "active", NULL };
  210. int ret, value;
  211. char *env;
  212. env = starpu_getenv("OMP_WAIT_POLICY");
  213. if (!env)
  214. return;
  215. ret = read_string_var(env, strings, &value);
  216. if (!ret)
  217. {
  218. fprintf(stderr, "StarPU: Invalid value for environment variable OMP_WAIT_POLICY\n");
  219. return;
  220. }
  221. _initial_icv_values.wait_policy_var = value;
  222. }
  223. static void read_display_env_var(int *dest)
  224. {
  225. const char *strings[] = { "false", "true", "verbose", NULL };
  226. int ret, value;
  227. char *env;
  228. env = starpu_getenv("OMP_DISPLAY_ENV");
  229. if (!env)
  230. return;
  231. ret = read_string_var(env, strings, &value);
  232. if (!ret)
  233. {
  234. fprintf(stderr, "StarPU: Invalid value for environment variable OMP_DISPLAY_ENV\n");
  235. return;
  236. }
  237. *dest = value;
  238. }
  239. static int convert_place_name(const char *str, size_t n)
  240. {
  241. static const char *strings[] = { "threads", "cores", "sockets", NULL };
  242. int mode = stringsn_cmp(strings, str, n);
  243. if (mode < 0)
  244. _STARPU_ERROR("place abstract name parse error\n");
  245. return mode+1; /* 0 is for undefined abstract name */
  246. }
  247. /* Note: this function modifies the string str */
  248. static void read_a_place_name(char *str, struct starpu_omp_place *places)
  249. {
  250. int i = 0;
  251. /* detect exclusion of abstract name expressed as '!' prefix */
  252. if (str[i] == '!')
  253. {
  254. places->abstract_excluded = 1;
  255. i++;
  256. }
  257. else
  258. {
  259. places->abstract_excluded = 0;
  260. }
  261. /* detect length value for abstract name expressed as '(length)' suffix) */
  262. char *begin_length_spec = strchr(str+i,'(');
  263. if (begin_length_spec != NULL)
  264. {
  265. char *end_length_spec = strrchr(begin_length_spec+1, ')');
  266. if (end_length_spec == NULL || end_length_spec <= begin_length_spec+1)
  267. _STARPU_ERROR("parse error in places list\n");
  268. *begin_length_spec = '\0';
  269. *end_length_spec = '\0';
  270. errno = 0;
  271. int v = (int)strtol(begin_length_spec+1, NULL, 10);
  272. if (errno != 0)
  273. _STARPU_ERROR("parse error in places list\n");
  274. places->abstract_length = v;
  275. }
  276. else
  277. {
  278. places->abstract_length = 1;
  279. }
  280. /* convert abstract place name string to corresponding value */
  281. {
  282. int mode = convert_place_name(str+i, strlen(str+i));
  283. STARPU_ASSERT(mode >= starpu_omp_place_threads && mode <= starpu_omp_place_sockets);
  284. places->abstract_name = mode;
  285. places->numeric_places = NULL;
  286. places->nb_numeric_places = 0;
  287. }
  288. }
  289. static void read_a_places_list(const char *str, struct starpu_omp_place *places)
  290. {
  291. if (str[0] == '\0')
  292. {
  293. places->numeric_places = NULL;
  294. places->nb_numeric_places = 0;
  295. places->abstract_name = starpu_omp_place_undefined;
  296. return;
  297. }
  298. enum { state_split,
  299. state_read_brace_prefix,
  300. state_read_opening_brace,
  301. state_read_numeric_prefix,
  302. state_read_numeric,
  303. state_split_numeric,
  304. state_read_closing_brace,
  305. state_read_brace_suffix,
  306. };
  307. struct starpu_omp_numeric_place *places_list = NULL;
  308. int places_list_size = 0;
  309. int nb_places = 0;
  310. int *included_items_list = NULL;
  311. int included_items_list_size = 0;
  312. int nb_included_items = 0;
  313. int *excluded_items_list = NULL;
  314. int excluded_items_list_size = 0;
  315. int nb_excluded_items = 0;
  316. int exclude_place_flag = 0;
  317. int exclude_item_flag = 0;
  318. int i = 0;
  319. int state = state_read_brace_prefix;
  320. while (1)
  321. {
  322. switch (state)
  323. {
  324. /* split a comma separated list of numerical places */
  325. case state_split:
  326. if (str[i] == '\0')
  327. {
  328. goto eol;
  329. }
  330. else if (str[i] != ',')
  331. _STARPU_ERROR("parse error in places list\n");
  332. i++;
  333. state = state_read_brace_prefix;
  334. break;
  335. /* read optional exclude flag '!' for numerical place */
  336. case state_read_brace_prefix:
  337. exclude_place_flag = 0;
  338. if (str[i] == '!')
  339. {
  340. exclude_place_flag = 1;
  341. i++;
  342. }
  343. state = state_read_opening_brace;
  344. break;
  345. /* read place opening brace */
  346. case state_read_opening_brace:
  347. if (str[i] != '{')
  348. _STARPU_ERROR("parse error in places list\n");
  349. i++;
  350. state = state_read_numeric_prefix;
  351. break;
  352. /* read optional exclude flag '!' for numerical item */
  353. case state_read_numeric_prefix:
  354. exclude_item_flag = 0;
  355. if (str[i] == '!')
  356. {
  357. exclude_item_flag = 1;
  358. i++;
  359. }
  360. state = state_read_numeric;
  361. break;
  362. /* read numerical item */
  363. case state_read_numeric:
  364. {
  365. char *endptr = NULL;
  366. errno = 0;
  367. int v = (int)strtol(str+i, &endptr, 10);
  368. if (errno != 0)
  369. _STARPU_ERROR("parse error in places list, strtol failed with error %s\n", strerror(errno));
  370. if (exclude_item_flag)
  371. {
  372. if (excluded_items_list_size == 0)
  373. {
  374. excluded_items_list_size = _STARPU_INITIAL_PLACE_ITEMS_LIST_SIZE;
  375. _STARPU_MALLOC(excluded_items_list, excluded_items_list_size * sizeof(int));
  376. }
  377. else if (nb_excluded_items == excluded_items_list_size)
  378. {
  379. excluded_items_list_size *= 2;
  380. _STARPU_REALLOC(excluded_items_list, excluded_items_list_size * sizeof(int));
  381. }
  382. excluded_items_list[nb_excluded_items] = v;
  383. nb_excluded_items++;
  384. }
  385. else
  386. {
  387. if (included_items_list_size == 0)
  388. {
  389. included_items_list_size = _STARPU_INITIAL_PLACE_ITEMS_LIST_SIZE;
  390. _STARPU_MALLOC(included_items_list, included_items_list_size * sizeof(int));
  391. }
  392. else if (nb_included_items == included_items_list_size)
  393. {
  394. included_items_list_size *= 2;
  395. _STARPU_REALLOC(included_items_list, included_items_list_size * sizeof(int));
  396. }
  397. included_items_list[nb_included_items] = v;
  398. nb_included_items++;
  399. }
  400. exclude_item_flag = 0;
  401. i = endptr - str;
  402. state = state_split_numeric;
  403. }
  404. break;
  405. /* read comma separated or colon separated numerical item list */
  406. case state_split_numeric:
  407. if (str[i] == ':')
  408. /* length and stride colon separated arguments not supported for now */
  409. _STARPU_ERROR("colon support unimplemented in numeric place list");
  410. if (str[i] == ',')
  411. {
  412. i++;
  413. state = state_read_numeric_prefix;
  414. }
  415. else
  416. {
  417. state = state_read_closing_brace;
  418. }
  419. break;
  420. /* read end of numerical item list */
  421. case state_read_closing_brace:
  422. if (str[i] != '}')
  423. _STARPU_ERROR("parse error in places list\n");
  424. if (places_list_size == 0)
  425. {
  426. places_list_size = _STARPU_INITIAL_PLACES_LIST_SIZE;
  427. _STARPU_MALLOC(places_list, places_list_size * sizeof(*places_list));
  428. }
  429. else if (nb_places == places_list_size)
  430. {
  431. places_list_size *= 2;
  432. _STARPU_REALLOC(places_list, places_list_size * sizeof(*places_list));
  433. }
  434. places_list[nb_places].excluded_place = exclude_place_flag;
  435. places_list[nb_places].included_numeric_items = included_items_list;
  436. places_list[nb_places].nb_included_numeric_items = nb_included_items;
  437. places_list[nb_places].excluded_numeric_items = excluded_items_list;
  438. places_list[nb_places].nb_excluded_numeric_items = nb_excluded_items;
  439. nb_places++;
  440. exclude_place_flag = 0;
  441. included_items_list = NULL;
  442. included_items_list_size = 0;
  443. nb_included_items = 0;
  444. excluded_items_list = NULL;
  445. excluded_items_list_size = 0;
  446. nb_excluded_items = 0;
  447. i++;
  448. state = state_read_brace_suffix;
  449. break;
  450. /* read optional place colon separated suffix */
  451. case state_read_brace_suffix:
  452. if (str[i] == ':')
  453. /* length and stride colon separated arguments not supported for now */
  454. _STARPU_ERROR("colon support unimplemented in numeric place list");
  455. state = state_split;
  456. break;
  457. default:
  458. _STARPU_ERROR("invalid state in parsing places list\n");
  459. }
  460. }
  461. eol:
  462. places->numeric_places = places_list;
  463. places->nb_numeric_places = nb_places;
  464. places->abstract_name = starpu_omp_place_numerical;
  465. }
  466. static void convert_places_string(const char *_str, struct starpu_omp_place *places)
  467. {
  468. char *str = strdup(_str);
  469. if (str == NULL)
  470. _STARPU_ERROR("memory allocation failed\n");
  471. remove_spaces(str);
  472. if (str[0] != '\0')
  473. {
  474. /* check whether this is the start of an abstract name */
  475. if (isalpha(str[0]) || (str[0] == '!' && isalpha(str[1])))
  476. {
  477. read_a_place_name(str, places);
  478. }
  479. /* else the string must contain a list of braces */
  480. else
  481. {
  482. read_a_places_list(str, places);
  483. }
  484. }
  485. free(str);
  486. }
  487. static void free_places(struct starpu_omp_place *places)
  488. {
  489. int i;
  490. for (i = 0; i < places->nb_numeric_places; i++)
  491. {
  492. if (places->numeric_places[i].nb_included_numeric_items > 0)
  493. {
  494. free(places->numeric_places[i].included_numeric_items);
  495. }
  496. if (places->numeric_places[i].nb_excluded_numeric_items > 0)
  497. {
  498. free(places->numeric_places[i].excluded_numeric_items);
  499. }
  500. }
  501. if (places->nb_numeric_places > 0)
  502. {
  503. free(places->numeric_places);
  504. }
  505. }
  506. static void read_proc_bind_var()
  507. {
  508. static const char *strings[] = { "false", "true", "master", "close", "spread", NULL };
  509. const int max_levels = _initial_icv_values.max_active_levels_var + 1;
  510. int *bind_list = NULL;
  511. char *env;
  512. _STARPU_CALLOC(bind_list, max_levels, sizeof(*bind_list));
  513. env = starpu_getenv("OMP_PROC_BIND");
  514. if (env)
  515. {
  516. char *saveptr, *token;
  517. int level = 0;
  518. token = strtok_r(env, ",", &saveptr);
  519. for (; token != NULL; token = strtok_r(NULL, ",", &saveptr))
  520. {
  521. int value;
  522. if (!read_string_var(token, strings, &value))
  523. {
  524. fprintf(stderr, "StarPU: Invalid value for environment variable OMP_PROC_BIND\n");
  525. break;
  526. }
  527. bind_list[level++] = value;
  528. }
  529. }
  530. _initial_icv_values.bind_var = bind_list;
  531. }
  532. static void read_num_threads_var()
  533. {
  534. const int max_levels = _initial_icv_values.max_active_levels_var + 1;
  535. int *num_threads_list = NULL;
  536. char *env;
  537. _STARPU_CALLOC(num_threads_list, max_levels, sizeof(*num_threads_list));
  538. env = starpu_getenv("OMP_NUM_THREADS");
  539. if (env)
  540. {
  541. char *saveptr, *token;
  542. int level = 0;
  543. token = strtok_r(env, ",", &saveptr);
  544. for (; token != NULL; token = strtok_r(NULL, ",", &saveptr))
  545. {
  546. int value;
  547. if (!read_int_var(token, &value))
  548. {
  549. fprintf(stderr, "StarPU: Invalid value for environment variable OMP_NUM_THREADS\n");
  550. break;
  551. }
  552. num_threads_list[level++] = value;
  553. }
  554. }
  555. _initial_icv_values.nthreads_var = num_threads_list;
  556. }
  557. static void read_omp_int_var(const char *name, int *icv)
  558. {
  559. int ret, value;
  560. char *env;
  561. env = starpu_getenv(name);
  562. if (!env)
  563. return;
  564. ret = read_int_var(env, &value);
  565. if (!ret || value < 0)
  566. {
  567. fprintf(stderr, "StarPU: Invalid value for environment variable %s\n", name);
  568. return;
  569. }
  570. *icv = value;
  571. }
  572. static void read_omp_boolean_var(const char *name, int *icv)
  573. {
  574. const char *strings[] = { "false", "true", NULL };
  575. int ret, value;
  576. char *env;
  577. env = starpu_getenv(name);
  578. if (!env)
  579. return;
  580. ret = read_string_var(env, strings, &value);
  581. if (!ret)
  582. {
  583. fprintf(stderr, "StarPU: Invalid value for environment variable %s\n", name);
  584. return;
  585. }
  586. *icv = value;
  587. }
  588. static void read_omp_environment(void)
  589. {
  590. read_omp_boolean_var("OMP_DYNAMIC", &_initial_icv_values.dyn_var);
  591. read_omp_boolean_var("OMP_NESTED", &_initial_icv_values.nest_var);
  592. read_sched_var("OMP_SCHEDULE", &_initial_icv_values.run_sched_var, &_initial_icv_values.run_sched_chunk_var);
  593. read_size_var("OMP_STACKSIZE", &_initial_icv_values.stacksize_var);
  594. read_wait_policy_var();
  595. read_omp_int_var("OMP_THREAD_LIMIT", &_initial_icv_values.thread_limit_var);
  596. read_omp_int_var("OMP_MAX_ACTIVE_LEVELS", &_initial_icv_values.max_active_levels_var);
  597. read_omp_boolean_var("OMP_CANCELLATION", &_initial_icv_values.cancel_var);
  598. read_omp_int_var("OMP_DEFAULT_DEVICE", &_initial_icv_values.default_device_var);
  599. read_omp_int_var("OMP_MAX_TASK_PRIORITY", &_initial_icv_values.max_task_priority_var);
  600. /* Avoid overflow e.g. in num_threads_list allocation */
  601. STARPU_ASSERT_MSG(_initial_icv_values.max_active_levels_var > 0 && _initial_icv_values.max_active_levels_var < 1000000, "OMP_MAX_ACTIVE_LEVELS should have a reasonable value");
  602. /* TODO: check others */
  603. read_proc_bind_var();
  604. read_num_threads_var();
  605. /* read OMP_PLACES */
  606. {
  607. memset(&_initial_icv_values.places, 0, sizeof(_initial_icv_values.places));
  608. _initial_icv_values.places.abstract_name = starpu_omp_place_undefined;
  609. const char *env = starpu_getenv("OMP_PLACES");
  610. if (env)
  611. {
  612. convert_places_string(env, &_initial_icv_values.places);
  613. }
  614. }
  615. _starpu_omp_initial_icv_values = &_initial_icv_values;
  616. }
  617. static void free_omp_environment(void)
  618. {
  619. /**/
  620. _starpu_omp_initial_icv_values = NULL;
  621. /* OMP_DYNAMIC */
  622. /* OMP_NESTED */
  623. /* OMP_SCHEDULE */
  624. /* OMP_STACKSIZE */
  625. /* OMP_WAIT_POLICY */
  626. /* OMP_THREAD_LIMIT */
  627. /* OMP_MAX_ACTIVE_LEVELS */
  628. /* OMP_CANCELLATION */
  629. /* OMP_DEFAULT_DEVICE */
  630. /* OMP_MAX_TASK_PRIORITY */
  631. /* OMP_PROC_BIND */
  632. free(_initial_icv_values.bind_var);
  633. _initial_icv_values.bind_var = NULL;
  634. /* OMP_NUM_THREADS */
  635. free(_initial_icv_values.nthreads_var);
  636. _initial_icv_values.nthreads_var = NULL;
  637. /* OMP_PLACES */
  638. free_places(&_initial_icv_values.places);
  639. }
  640. static void display_omp_environment(int verbosity_level)
  641. {
  642. if (verbosity_level > 0)
  643. {
  644. printf("OPENMP DISPLAY ENVIRONMENT BEGIN\n");
  645. printf(" _OPENMP = 'xxxxxx'\n");
  646. printf(" [host] OMP_DYNAMIC = '%s'\n", _starpu_omp_initial_icv_values->dyn_var?"TRUE":"FALSE");
  647. printf(" [host] OMP_NESTED = '%s'\n", _starpu_omp_initial_icv_values->nest_var?"TRUE":"FALSE");
  648. printf(" [host] OMP_SCHEDULE = '");
  649. switch (_starpu_omp_initial_icv_values->run_sched_var)
  650. {
  651. case starpu_omp_sched_static:
  652. printf("STATIC, %llu", _starpu_omp_initial_icv_values->run_sched_chunk_var);
  653. break;
  654. case starpu_omp_sched_dynamic:
  655. printf("DYNAMIC, %llu", _starpu_omp_initial_icv_values->run_sched_chunk_var);
  656. break;
  657. case starpu_omp_sched_guided:
  658. printf("GUIDED, %llu", _starpu_omp_initial_icv_values->run_sched_chunk_var);
  659. break;
  660. case starpu_omp_sched_auto:
  661. printf("AUTO, %llu", _starpu_omp_initial_icv_values->run_sched_chunk_var);
  662. break;
  663. case starpu_omp_sched_undefined:
  664. default:
  665. break;
  666. }
  667. printf("'\n");
  668. printf(" [host] OMP_STACKSIZE = '%d'\n", _starpu_omp_initial_icv_values->stacksize_var);
  669. printf(" [host] OMP_WAIT_POLICY = '%s'\n", _starpu_omp_initial_icv_values->wait_policy_var?"ACTIVE":"PASSIVE");
  670. printf(" [host] OMP_MAX_ACTIVE_LEVELS = '%d'\n", _starpu_omp_initial_icv_values->max_active_levels_var);
  671. printf(" [host] OMP_CANCELLATION = '%s'\n", _starpu_omp_initial_icv_values->cancel_var?"TRUE":"FALSE");
  672. printf(" [host] OMP_DEFAULT_DEVICE = '%d'\n", _starpu_omp_initial_icv_values->default_device_var);
  673. printf(" [host] OMP_MAX_TASK_PRIORITY = '%d'\n", _starpu_omp_initial_icv_values->max_task_priority_var);
  674. printf(" [host] OMP_PROC_BIND = '");
  675. {
  676. int level;
  677. for (level = 0; level < _starpu_omp_initial_icv_values->max_active_levels_var; level++)
  678. {
  679. if (level > 0)
  680. {
  681. printf(", ");
  682. }
  683. switch (_starpu_omp_initial_icv_values->bind_var[level])
  684. {
  685. case starpu_omp_proc_bind_false:
  686. printf("FALSE");
  687. break;
  688. case starpu_omp_proc_bind_true:
  689. printf("TRUE");
  690. break;
  691. case starpu_omp_proc_bind_master:
  692. printf("MASTER");
  693. break;
  694. case starpu_omp_proc_bind_close:
  695. printf("CLOSE");
  696. break;
  697. case starpu_omp_proc_bind_spread:
  698. printf("SPREAD");
  699. break;
  700. default:
  701. break;
  702. }
  703. }
  704. }
  705. printf("'\n");
  706. printf(" [host] OMP_NUM_THREADS = '");
  707. {
  708. int level;
  709. for (level = 0; level < _starpu_omp_initial_icv_values->max_active_levels_var; level++)
  710. {
  711. if (level > 0)
  712. {
  713. printf(", ");
  714. }
  715. printf("%d", _starpu_omp_initial_icv_values->nthreads_var[level]);
  716. }
  717. }
  718. printf("'\n");
  719. printf(" [host] OMP_PLACES = '");
  720. {
  721. struct starpu_omp_place *places = &_starpu_omp_initial_icv_values->places;
  722. if (places->nb_numeric_places > 0)
  723. {
  724. int p;
  725. for (p = 0; p < places->nb_numeric_places; p++)
  726. {
  727. if (p > 0)
  728. {
  729. printf(",");
  730. }
  731. struct starpu_omp_numeric_place *np = &places->numeric_places[p];
  732. if (np->excluded_place)
  733. {
  734. printf("!");
  735. }
  736. printf("{");
  737. int i;
  738. for (i = 0; i < np->nb_included_numeric_items; i++)
  739. {
  740. if (i > 0)
  741. {
  742. printf(",");
  743. }
  744. printf("%d", np->included_numeric_items[i]);
  745. }
  746. for (i = 0; i < np->nb_excluded_numeric_items; i++)
  747. {
  748. if (i > 0 || np->nb_included_numeric_items)
  749. {
  750. printf(",");
  751. }
  752. printf("!%d", np->excluded_numeric_items[i]);
  753. }
  754. printf("}");
  755. /* TODO: print length/stride suffix */
  756. }
  757. }
  758. else
  759. {
  760. if (places->abstract_excluded)
  761. {
  762. printf("!");
  763. }
  764. switch (places->abstract_name)
  765. {
  766. case starpu_omp_place_threads:
  767. printf("THREADS");
  768. break;
  769. case starpu_omp_place_cores:
  770. printf("CORES");
  771. break;
  772. case starpu_omp_place_sockets:
  773. printf("SOCKETS");
  774. break;
  775. case starpu_omp_place_numerical:
  776. printf("<NUMERICAL>");
  777. break;
  778. case starpu_omp_place_undefined:
  779. default:
  780. break;
  781. }
  782. if (places->abstract_length)
  783. {
  784. printf("(%d)", places->abstract_length);
  785. }
  786. }
  787. }
  788. printf("'\n");
  789. printf(" [host] OMP_THREAD_LIMIT = '%d'\n", _initial_icv_values.thread_limit_var);
  790. if (verbosity_level > 1)
  791. {
  792. /* no vendor specific runtime variable */
  793. }
  794. printf("OPENMP DISPLAY ENVIRONMENT END\n");
  795. }
  796. }
  797. void _starpu_omp_environment_init(void)
  798. {
  799. read_omp_environment();
  800. int display_env = 0;
  801. read_display_env_var(&display_env);
  802. if (display_env > 0)
  803. {
  804. display_omp_environment(display_env);
  805. }
  806. }
  807. void _starpu_omp_environment_exit(void)
  808. {
  809. free_omp_environment();
  810. }
  811. #endif /* STARPU_OPENMP */