Home > pthread setaffinity np error > pthread_setaffinity_np error 22

Pthread_setaffinity_np Error 22

Contents

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business

Pthread_setaffinity_np Vs Sched_setaffinity

Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation pthread_setaffinity_np example Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like

Cpu_set_t

you, helping each other. Join them; it only takes a minute: Sign up Pthread_setaffinity_np invalid argument up vote 2 down vote favorite I am trying to change the affinity of each thread inside the start routine. Here's cpu_zero the code. In the below code, 't' is the argument passed through the pthread_create function. cpu_set_t mask; pthread_t c; a = *((int *)t); printf(" thread no. is %d \n",a); CPU_ZERO(&mask); a =a/2 + 1; CPU_SET(a,&mask); c=pthread_self(); s=pthread_setaffinity_np(c,sizeof(cpu_set_t), &mask); if (s!=0) handle_error_en(s,"pthread_setaffinity_np"); The thread affinity is not getting changed. Where am I going wrong? c++ c pthreads setthreadaffinitymask share|improve this question edited Jan 20 '12 at 12:49 BЈовић 36.4k23100176 asked Jan 16 '12 at 21:50 akhil28288 10710 sched_setaffinity example You can replace the entire switch statement with CPU_SET((a/2+1), &mask);, by the way. –Daniel Fischer Jan 16 '12 at 21:57 Ohh Thanks... :P –akhil28288 Jan 16 '12 at 21:59 Perhaps better, to be sure it's evaluated only once, a = a/2+1; CPU_SET(a, &mask);. –Daniel Fischer Jan 16 '12 at 22:05 1 You're passing the same int pointer to all the threads, which all dereference it some time later, after the int has changed. –bk1e Jan 17 '12 at 3:00 1 Also, maybe the function that created the threads returns before they read the int, and something else uses the same stack location. –bk1e Jan 17 '12 at 3:03 | show 3 more comments 1 Answer 1 active oldest votes up vote 1 down vote accepted I had misunderstood the bounds of the mask. That was where I was going wrong. share|improve this answer answered Jan 31 '12 at 22:13 akhil28288 10710 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions

int cpusetsize, const cpu_set_t *mask); int pthread_getaffinity_np(pthread_t tid, int cpusetsize, cpu_set_t *mask); Description pthread_setaffinity_np sets the CPU affinity mask of the thread whose ID is tid to the

Set Affinity Linux Example

value specified by mask. The argument cpusetsize is the length (in bytes) pthread_attr_setaffinity_np of the data pointed to by mask. Normally this argument would be specified as sizeof(cpu_set_t). If the

Pthread_attr_setaffinity_np Example

thread specified by tid is not currently running on one of the CPUs specified in mask, then that thread is migrated to one of the CPUs specified in mask. After http://stackoverflow.com/questions/8886778/pthread-setaffinity-np-invalid-argument a call to pthread_setaffinity_np, the set of CPUs on which the thread will actually run is the intersection of the set specified in the mask argument and the set of CPUs actually present on the system. pthread_getaffinity_np writes the affinity mask of the thread whose ID is tid into the cpu_set_t structure pointed to by mask. The cpusetsize argument http://www.sourceware.org/pthreads-win32/manual/pthread_setaffinity_np.html specifies the size (in bytes) of mask. Pthreads-w32 currently ignores the cpusetsize parameter for either function because cpu_set_t is a direct typeset to the Windows affinity vector type DWORD_PTR. Return Value On success, pthread_setaffinity_np and pthread_getaffinity_np return 0. On error, an error number is returned. Errors EFAULT A supplied memory address was invalid. EINVAL The affinity bit mask mask contains no processors that are currently physically on the system. EAGAIN The function did not succeed in changing or obtaining the CPU affinity for some undetermined reason. Try again. EPERM The calling process does not have appropriate privileges. ESRCH The thread whose ID is tid could not be found. Application Usage A thread's CPU affinity mask determines the set of CPUs on which it is eligible to run. On a multiprocessor system, setting the CPU affinity mask can be used to obtain performance benefits. For example, by dedicating one CPU to a particular thread (i.e., setting the affinity mask of that thread to specify a single CPU, and setting the affinity mask of all other thr

LearningModern CodeNetworkingOpen SourceStorageToolsDeveloper TypeEmbedded SystemsGame DevMediaTechnical, Enterprise, HPCWebOSAll ToolsAndroid*HTML5Linux*OS X*Windows*ResourcesCode SamplesContact SupportDocumentationFree SoftwareIntel Registration CenterProduct ForumsSDKsResourcesPartner with IntelAcademic ProgramPartner SpotlightBlack Belt DeveloperDeveloper MeshInnovator ProgramSuccess StoriesLearnBlogBusiness TipsEventsVideosSupportContact SupportDeveloper EvangelistsFAQsForums Search form Search You are hereHome › Forums › Platform and Technology Discussion › Intel® https://software.intel.com/en-us/forums/intel-many-integrated-core/topic/536182 Many Integrated Core Architecture (Intel MIC Architecture) FacebookLinkedInTwitterDiggDeliciousGoogle Plus Core pinning with pthread Core pinning with pthread Jun Hyun S. Fri, 11/21/2014 - 01:19 Hi all, I did some follow-up on my last topic https://software.intel.com/en-us/forums/topic/533886  Long story short, I'm trying to emulate SIMD behavior in MIC environment, and I actually decided to implement the offloaded segment in native code without OpenMP pragmas, which means pthread_setaffinity_np error I'm implementing thread pinning to individual cores with pthread_attr_setaffinity_np. The logic is all there from start to finish. Here's what I did: 1. I got the number of logical cores using sysconf (_SC_NPROCESSORS_ONLN), which returns 240 (a 60-core 5110P). 2. Based on the parameters [range of cores to utilize] and [number of active threads per core], I pin the necessary number of threads (computed pthread_setaffinity_np error 22 from another user parameter) to the respective cores using pthread_attr_setaffinity_np(). (I even did the rotate-by-one trick to make sure the pinning starts from the first thread of the first core, so when I say logical core 0, it does mean thread 0 of core 0) 3. Start infinite loop where spawned threads are in an infinite loop with synchronization per each iteration with the parent process using pthread_barrier_wait() The current problem lies in step 2. I've created a pool of 'pthread_attr_t's for each pinning to logical core (240 attr variables), and when I try to initialize them with pthread_attr_setaffinity_np(), it returns error code 22: Invalid argument. It is important to mention that it does not fail from the get go. The pthread_attr_setaffinity_np() call runs smoothly from logical core 0 to logical core 106, but it fails on initialization for logical core 107. The man page for pthread_attr_setaffinity_np() suggests that EINVAL is returned when the CPU set is out of range and the CONFIG_NR_CPUS is in charge of the range. Another search told me that the variable can be checked in file /boot/config-`uname -r` AFAIK, however, there was no wa

 

Related content

pthread_setaffinity_np error

Pthread setaffinity np Error table id toc tbody tr td div id toctitle Contents div ul li a href Pthread setaffinity Example a li li a href Cpu zero a li li a href Pthread setaffinity np Android a li ul td tr tbody table p size t cpusetsize const cpu set t cpuset int pthread getaffinity np pthread t thread size t cpusetsize cpu set t cpuset Compile and link with -pthread Description The pthread setaffinity np function sets the CPU affinity mask of the thread thread to the CPU relatedl set pointed to by cpuset If the call