Intel® oneAPI Base Toolkit
Support for core tools and libraries to build and deploy high-performance data-centric applications

Core islolation using CPU_SET

rganti
Beginner
483 Views

Hi, 

I am trying to do core isolation and core pinning using the following code on a Linux (ubuntu system)


#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <unistd.h> /* sysconf(3) */
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#define _GNU_SOURCE
#include <sched.h>
#include <assert.h>
 
int main()
{
cpu_set_t mask;
CPU_ZERO(&mask);
CPU_SET(6, &mask); // core number can be according to your priority
int result = sched_setaffinity(0, sizeof(mask), &mask);
long nproc = sysconf(_SC_NPROCESSORS_ONLN);
printf("Active CPUs: ");
for (int i = 0; i < nproc; i++)
printf("%d ", CPU_ISSET(i, &mask));
printf("\n");
}
 
 

When I compile the above program using icx , I am getting the following error. Not sure what to include for this compiler.

icx    -g  -fast  test2.c

test2.c:16:5: error: call to undeclared function 'CPU_ZERO'; ISO C99 and later do not support implicit functio
n declarations [-Wimplicit-function-declaration]
   CPU_ZERO(&mask);
   ^
test2.c:17:5: error: call to undeclared function 'CPU_SET'; ISO C99 and later do not support implicit function
declarations [-Wimplicit-function-declaration]
   CPU_SET(6, &mask); // core number can be according to your priority
   ^
test2.c:18:18: error: call to undeclared function 'sched_setaffinity'; ISO C99 and later do not support implic
it function declarations [-Wimplicit-function-declaration]
   int result = sched_setaffinity(0, sizeof(mask), &mask);
                ^
test2.c:22:23: error: call to undeclared function 'CPU_ISSET'; ISO C99 and later do not support implicit funct
ion declarations [-Wimplicit-function-declaration]
       printf("%d ", CPU_ISSET(i, &mask));
                     ^

 

0 Kudos
5 Replies
AishwaryaCV_Intel
Moderator
450 Views

Hi,

 

Thanks for posting in the Intel forums.

 

Could you please let us know the Intel oneAPI version you have been using?

 

Could you please try with the icpx compiler and let us know if you further have any issues?

 

For more details please refer the below link

 

https://www.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-cpp-compiler-dev-guide-an...


Thanks And Regards,

Aishwarya


rganti
Beginner
409 Views

Hi Aishwarya

 

Intel API version is

 

icx --version
Intel(R) oneAPI DPC++/C++ Compiler 2022.2.1 (2022.2.1.20221020)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/intel/oneapi/compiler/2022.2.1/linux/bin-llvm
Configuration file: /opt/intel/oneapi/compiler/2022.2.1/linux/bin/icx.cfg

 

I have other problems if I use CPP compiler. 

 

I was anyway able to get over the issue by using the additional flags: -Wall -D_GNU_SOURCE  

 

I am not sure if this is the correct way of doing things.

 

Regards

RK

AishwaryaCV_Intel
Moderator
379 Views

Hi rganti,


_GNU_SOURCE needs to be defined before including header files like,

#define _GNU_SORCE

#include <stdio.h>

#include <stdlib.h>

In the above code you mentioned _GNU_SOURCE is defined after including header files,

so kindly check by defining at the top to ressolve the issue


Or other way to enable _GNU_SOURCE is by using -D_GNU_SOURCE flag 


Thanks And regards

Aishwarya



AishwaryaCV_Intel
Moderator
322 Views

Hi,

 

Could you please let us know whether your issue is resolved or not.If yes,make sure to accept this as a solution.

 

Thanks & Regards

Aishwarya


AishwaryaCV_Intel
Moderator
275 Views

Hi,


We assume that your issue is resolved. If you need any additional information, please post a new question as this thread will no longer be monitored by Intel.


Thanks and Regards,

Aishwarya


Reply