/****** shepherd_binding/create_binding_env_linux() **************************** * NAME * create_binding_env_linux() -- Creates SGE_BINDING env variable. * * SYNOPSIS * bool create_binding_env_linux(const int* proc_id, const int amount) * * FUNCTION * Creates the SGE_BINDING environment variable on Linux operating system. * This environment variable contains a space separated list of Linux * internal processor ids given as input parameter. * * INPUTS * const int* proc_id - List of processor ids. * const int amount - Length of processor id list. * * RESULT * bool - true when SGE_BINDING env var could be generated false if not * * NOTES * MT-NOTE: create_binding_env_linux() is MT safe * *******************************************************************************/ bool create_binding_env_linux(const int* proc_id, const int amount) { bool retval = true; dstring sge_binding = DSTRING_INIT; dstring proc = DSTRING_INIT; int i; for (i = 0; i < amount; i++) { sge_dstring_clear(&proc); /* DG TODO env ends with whitespace char */ sge_dstring_sprintf(&proc, "%d ", proc_id[i]); sge_dstring_append_dstring(&sge_binding, &proc); } if (sge_setenv("SGE_BINDING", sge_dstring_get_string(&sge_binding)) != 1) { /* settting env var was not successful */ retval = false; shepherd_trace("create_binding_env_linux: Couldn't set environment variable!"); } sge_dstring_free(&sge_binding); sge_dstring_free(&proc); return retval; }
/****** shepherd_binding/create_binding_env() **************************** * NAME * create_binding_env() -- Creates SGE_BINDING env variable. * * SYNOPSIS * bool create_binding_env(hwloc_const_bitmap_t set) * * FUNCTION * Creates the SGE_BINDING environment variable. * This environment variable contains a space-separated list of * internal processor ids given as input parameter. * * INPUTS * hwloc_const_bitmap_t set - CPU set to use * * RESULT * bool - true when SGE_BINDING env var could be generated false if not * * NOTES * MT-NOTE: create_binding_env() is MT safe * *******************************************************************************/ static bool create_binding_env(hwloc_const_bitmap_t set) { bool retval = true; dstring sge_binding = DSTRING_INIT; dstring proc = DSTRING_INIT; unsigned i; bool first = true; hwloc_bitmap_foreach_begin(i, set) if (first) { first = false; sge_dstring_sprintf(&proc, "%d", i); } else { sge_dstring_sprintf(&proc, " %d", i); } sge_dstring_append_dstring(&sge_binding, &proc); hwloc_bitmap_foreach_end(); if (sge_setenv("SGE_BINDING", sge_dstring_get_string(&sge_binding)) != 1) { /* settting env var was not successful */ retval = false; shepherd_trace("create_binding_env: Couldn't set environment variable!"); } sge_dstring_free(&sge_binding); sge_dstring_free(&proc); return retval; }