Compile a C program with GCC, so that it can use all cpu cores in linux

后端 未结 4 1004
孤独总比滥情好
孤独总比滥情好 2020-12-16 08:35

I have a sample C program for addition. When I compile and run it with GCC it is using only one CPU core.

Is there any way to compile a C program so that it can use

4条回答
  •  执笔经年
    2020-12-16 09:40

    You can create n ( n is number of cores assume) threads in your program and then you can set CPU affinity of each thread so that it is tied to particular CPU Core. sched_setaffinity or pthread_setaffinity_np is the one allows you to set CPU affinity.

提交回复
热议问题