How to set CPU affinity for a process from C or C++ in Linux?

You need to use sched_setaffinity(2). For example, to run on CPUs 0 and 2 only: #define _GNU_SOURCE #include <sched.h> cpu_set_t mask; CPU_ZERO(&mask); CPU_SET(0, &mask); CPU_SET(2, &mask); int result = sched_setaffinity(0, sizeof(mask), &mask); (0 for the first parameter means the current process, supply a PID if it’s some other process you want to control). See also … Read more

Is there a simple process-based parallel map for python?

I seems like what you need is the map method in multiprocessing.Pool(): map(func, iterable[, chunksize]) A parallel equivalent of the map() built-in function (it supports only one iterable argument though). It blocks till the result is ready. This method chops the iterable into a number of chunks which it submits to the process pool as … Read more