openmp_runtime_support_environment.c 22 KB

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