#include "mbconfig.h"
#include "ac/pthread.h"
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <iostream>
#include "myassert.h"
Go to the source code of this file.
Definition at line 56 of file task2cpu.cc.
References DEBUGCERR, and mbdyn_task2cpu_disabled.
61 pthread_mutex_lock(&::mbdyn_task2cpu_mutex);
65 fd = open(
"/dev/TASK2CPU", O_RDWR);
71 int save_errno = errno;
72 char *err_msg = strerror(save_errno);
74 silent_cerr(
"Error opening /dev/TASK2CPU ("
75 << save_errno <<
": " << err_msg <<
";"
76 " ignored)" << std::endl);
79 #elif defined(USE_PTHREAD_SETAFFINITY_NP)
82 CPU_SET(cpu, &cpuset);
84 const pthread_t thread = pthread_self();
86 int s = pthread_setaffinity_np(thread,
sizeof(cpuset), &cpuset);
89 silent_cerr(
"warning: pthread_setaffinity_np failed with status " << s << std::endl);
94 s = pthread_getaffinity_np(thread,
sizeof(cpuset), &cpuset);
97 DEBUGCERR(
"warning: pthread_getaffinity_np failed with status " << s << std::endl);
101 for (
int i = 0; i < CPU_SETSIZE; ++i) {
102 if (CPU_ISSET(i, &cpuset)) {
103 DEBUGCERR(
"thread " << cpu + 1 <<
" running at CPU " << i << std::endl);
114 silent_cerr(
"/dev/TASK2CPU or pthread_getaffinity_np are not available" << std::endl);
119 pthread_mutex_unlock(&::mbdyn_task2cpu_mutex);
static bool mbdyn_task2cpu_disabled