15 #include <sys/types.h> 48 char *env = getenv(
"EC_OVERWRITE_ENV");
50 *do_overwrite = atoi(env);
73 int j = (i &&
environ) ? (*i) : 0;
74 memset(value,
' ', valuelen);
75 if (j >= 1 && j <=
numenv) {
79 if (valuelen < len) len = valuelen;
104 char *p = malloc(slen+1);
106 fprintf(stderr,
"ec_getenv_(): Unable to allocate %d bytes of memory\n", slen+1);
107 ABOR1(
"ec_getenv_(): Unable to allocate memory");
111 memset(value,
' ', valuelen);
114 int len = strlen(env);
115 if (valuelen < len) len = valuelen;
116 memcpy(value,env,len);
138 const char *x = &s[slen-1];
140 while (slen > 0 && *x ==
' ') { --slen; --x; }
143 char *p = malloc(slen+1);
145 fprintf(stderr,
"ec_putenv_(): Unable to allocate %d bytes of memory\n", slen+1);
146 ABOR1(
"ec_putenv_(): Unable to allocate memory");
170 const char *x = &s[slen-1];
172 while (slen > 0 && *x ==
' ') { --slen; --x; }
176 char *p = malloc(slen+1);
178 fprintf(stderr,
"ec_putenv_nooverwrite_(): Unable to allocate %d bytes of memory\n", slen+1);
179 ABOR1(
"ec_putenv_nooverwrite_(): Unable to allocate memory");
216 return sleep((nsec && *nsec > 0) ? *nsec : 0);
233 t.tv_sec = usecs/1000000;
234 t.tv_usec = usecs%1000000;
235 (void) select(0, NULL, NULL, NULL, &t);
261 char s[HOST_NAME_MAX];
263 if (gethostname(s,
sizeof(s)) == 0) {
265 if (len > alen) len = alen;
279 #if defined(__GNUC__) 286 #include <sys/types.h> 287 #include <sys/syscall.h> 289 #if defined(RTLD_NEXT) 290 #define PTR_LIBC RTLD_NEXT 292 #define PTR_LIBC ((void*) -1L) 296 #define SYS_gettid __NR_gettid 300 pid_t tid = syscall(SYS_gettid);
308 char *env_procid = getenv(
"ALPS_APP_PE");
309 if (!env_procid) env_procid = getenv(
"EC_FARM_ID");
310 if (!env_procid) env_procid = getenv(
"PMI_RANK");
311 if (!env_procid) env_procid = getenv(
"OMPI_COMM_WORLD_RANK");
312 if (env_procid) me = atoi(env_procid);
323 pid_t
pid = getpid();
325 int master = (pid == tid) ? 1 : 0;
329 fprintf(stderr,
"***Error: Dynamic linking to pthread_attr_init() failed : errno = %d\n",errno);
333 if (!done && me == 0 && master) fp = stderr;
338 char *env_gs = getenv(
"THREAD_GUARDSIZE");
340 int pgsize = getpagesize();
341 size_t guardsize = atoll(env_gs);
342 if (strchr(env_gs,
'G')) guardsize *= 1073741824;
343 else if (strchr(env_gs,
'M')) guardsize *= 1048576;
344 else if (strchr(env_gs,
'K')) guardsize *= 1024;
345 guardsize = RNDUP(guardsize,pgsize);
347 "[%s@%s:%d] [pid=%ld:tid=%ld]: Requesting guard region size between thread stacks : %lld bytes (%s PAGESIZE = %d)\n",
348 __FUNCTION__,__FILE__,__LINE__,
349 (
long int)pid,(
long int)tid,
350 (
long long int)guardsize,
351 (guardsize > pgsize) ?
">" :
"<=",
353 if (guardsize > pgsize) {
354 char *env_omp = getenv(
"OMP_STACKSIZE");
355 size_t omp_stacksize = env_omp ? atoll(env_omp) : 0;
356 size_t stacksize = 0;
358 int iret = pthread_attr_getstacksize(attr,&stacksize);
363 if (strchr(env_omp,
'G')) omp_stacksize *= 1073741824;
364 else if (strchr(env_omp,
'M')) omp_stacksize *= 1048576;
365 else if (strchr(env_omp,
'K')) omp_stacksize *= 1024;
368 "[%s@%s:%d] [pid=%ld:tid=%ld]: Stack size(s) : %lld bytes (def), %lld bytes (OMP) : [iret=%d]\n",
369 __FUNCTION__,__FILE__,__LINE__,
370 (
long int)pid,(
long int)tid,
371 (
long long int)stacksize,
372 (
long long int)omp_stacksize,
374 if (iret == 0 && omp_stacksize > guardsize) {
376 iret = pthread_attr_setguardsize(attr,guardsize);
377 (void) pthread_attr_getguardsize(attr,&guardsize);
380 "[%s@%s:%d] [pid=%ld:tid=%ld]: Guard region size now : %lld bytes : [iret=%d]\n",
381 __FUNCTION__,__FILE__,__LINE__,
382 (
long int)pid,(
long int)tid,
383 (
long long int)guardsize,iret);
399 if (!done && me == 0) {
400 extern void meminfo_(
const int *,
const int *);
402 const int kstep = -1;
403 pid_t
pid = getpid();
405 int master = (pid == tid) ? 1 : 0;
406 if (me == 0 && master) meminfo_(&kout, &kstep);
void ec_microsleep(int usecs)
void ec_gethostname_(char a[], int alen)
void ec_usleep_(const int *usecs)
void ec_strenv(const int *i, char *value, const int valuelen)
void ec_putenv(const char *s, int slen)
static void MemInfoBeforeMain()
void ec_getenv(const char *s, char *value, int slen, const int valuelen)
void ec_gethostname(char a[], int alen)
void ec_putenv_nooverwrite_(const char *s, int slen)
void ec_putenv_(const char *s, int slen)
unsigned int ec_sleep(const int *nsec)
void ec_usleep(const int *usecs)
void ec_overwrite_env(int *do_overwrite)
void ec_overwrite_env_(int *do_overwrite)
int pthread_attr_init(pthread_attr_t *attr)
void __attribute__((constructor))
unsigned int ec_sleep_(const int *nsec)
static int(* ptr_pthread_attr_init)(pthread_attr_t *attr)
void ec_strenv_(const int *i, char *value, const int valuelen)
void ec_getenv_(const char *s, char *value, int slen, const int valuelen)
void ec_putenv_nooverwrite(const char *s, int slen)