36static void bump(
size_t begin,
size_t end,
void* user) {
37 int* items = (
int*)user;
40 for (i = begin; i < end; i++) items[i]++;
50static int all_ones(
const int* items,
size_t count) {
53 for (i = 0; i < count; i++)
54 if (items[i] != 1)
return 0;
65 a = calloc(1000000,
sizeof(
int));
66 b = calloc(1000000,
sizeof(
int));
67 if (!a || !b)
return 1;
72 expect_true(
"more than one slice on a machine with more than one core",
75 memset(a, 0, 1000000 *
sizeof(
int));
82 memset(a, 0, 1000000 *
sizeof(
int));
83 if (pthread_create(&other, NULL,
nested, b) != 0)
return 1;
85 pthread_join(other, NULL);
static void expect_true(const char *label, int cond)
static void * nested(void *arg)
a loop run from another thread, as a pool worker would
static void bump(size_t begin, size_t end, void *user)
add one to each item of the slice, so a slice done twice shows as a 2
static int all_ones(const int *items, size_t count)
every item is exactly one
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_ERR
error conditions
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL ).
#define LOG_NOTICE
normal but significant condition
int n_parallel_for(size_t begin, size_t end, size_t grain, N_PARALLEL_FN fn, void *user)
Run a loop over a range on several cores, and return when all of it is done.
long int get_nb_cpu_cores()
get number of core of current system
Common headers and low-level functions & define.