30 #include <sys/resource.h>
31 #include <sys/syscall.h>
48 static pid_t gettid(
void)
50 #if defined(__APPLE__)
52 pthread_threadid_np(NULL, &tid64);
53 pid_t tid = (pid_t)tid64;
55 pid_t tid = syscall(__NR_gettid);
65 int get_cpu_affinity(
void)
67 #ifdef HAVE_SCHED_GETAFFINITY
71 if (sched_getaffinity(gettid(),
sizeof(cpu_set_t),&coremask) != 0) {
72 fprintf(
stderr,
"Unable to get thread %d affinity. %s\n",gettid(),strerror(errno));
76 for (cpu=0;cpu < CPU_SETSIZE;cpu++) {
77 if (CPU_ISSET(cpu,&coremask)) {
89 int get_cpuset(
int fsz,
int *output,
int pe, _Bool debug)
91 #ifdef HAVE_SCHED_GETAFFINITY
95 if (sched_getaffinity(gettid(),
sizeof(cpu_set_t),&coremask) != 0) {
96 fprintf(
stderr,
"Unable to get thread %d affinity. %s\n",gettid(),strerror(errno));
103 for (cpu=0;cpu < CPU_SETSIZE;cpu++) {
104 if (CPU_ISSET(cpu,&coremask)) {
105 printf(
"=> get_cpuset - pe %d: %d\n",pe, cpu);
111 for (cpu=0;cpu < CPU_SETSIZE;cpu++) {
112 if (CPU_ISSET(cpu,&coremask)) {
129 int set_cpu_affinity(
int cpu)
131 #ifdef HAVE_SCHED_GETAFFINITY
135 CPU_SET(cpu,&coremask);
136 if (sched_setaffinity(gettid(),
sizeof(cpu_set_t),&coremask) != 0) {
integer function stderr()
This function returns the current standard fortran unit numbers for error messages.