1 subroutine util_getenv(env_name, env_value) 2* $Id$ 3 implicit none 4#include "errquit.fh" 5#include "stdio.fh" 6 character*(*) env_name ! [input] the name of the environment variable to check for 7 character*(*) env_value ! [output] the value of the named environement variable 8#if defined(CRAY) 9 integer*4 lname, lvalue, lerror 10#endif 11* 12#if defined(CRAY) 13 lname = 0 14 lvalue = 0 15 lerror = 0 16 call pxfgetenv(env_name,lname,env_value,lvalue,lerror) 17 if (lerror.eq.0) then ! 0 ok found env_name 18 return 19 else if (lerror.eq.22) then ! 22 env_name is not in environment 20 env_value = ' ' 21 return 22 else 23 call errquit('util_getenv:pxfgetenv fatal error', 24 * lerror, UNKNOWN_ERR) 25 endif 26#else 27 call getenv(env_name, env_value) 28#endif 29* 30 end 31 32#ifdef USE_OFFLOAD 33 integer function offload_span() 34 implicit none 35 character(64) env_string 36 integer span 37 integer stat 38 span = -1 39 call util_getenv('NWC_OFFLOAD_SPAN', env_string) 40 if ((len(env_string).ne.0).or.(env_string.ne.' ')) then 41 read (env_string,*,iostat=stat) span 42 endif 43 if (stat.ne.0) span = 1 44 if (span.lt.1) span = 1 45 offload_span = span 46 end 47#endif 48 49 50#ifdef USE_OFFLOAD 51c Thus function is a place holder for a function that 52c will assign offload capabilities to the calling GA rank. 53 logical function offload_enabled() 54 implicit none 55#include "global.fh" 56 character(64) env_string 57 integer span 58 external offload_span 59 integer offload_span 60 call util_getenv('NWC_NO_OFFLOAD', env_string) 61 if (env_string.eq.'T'.or.env_string.eq.'t'.or. 62 c env_string.eq.'1') then 63 offload_enabled=.false. 64 else 65 span = offload_span() 66 if (mod(ga_nodeid(), span).eq.0) then 67 offload_enabled=.true. 68 else 69 offload_enabled=.false. 70 endif 71 endif 72 end 73#endif 74 75 76c This function is a place holder for a function that 77c will assign actual offload devices to the GA rank w/ 78c offloading enabled. 79#ifdef USE_OFFLOAD 80 integer function offload_device() 81 implicit none 82#include "global.fh" 83#if USE_OPENMP 84 external offload_span 85 integer offload_span 86 integer omp_get_num_devices 87 external omp_get_num_devices 88 integer omp_get_default_device 89 external omp_get_default_device 90 external omp_set_default_device 91#endif 92 character(64) env_string 93 integer ndev 94 integer span 95 96 span = offload_span() 97#if USE_OPENMP 98 ndev = omp_get_num_devices() 99 offload_device = mod(ga_nodeid() / span, ndev) 100 call omp_set_default_device(offload_device) 101#else 102 offload_device = -1 103#endif 104 end 105#endif 106