20 int i1 = *(
const int *)v1;
21 int i2 = *(
const int *)v2;
25int main(
int argc,
char **argv) {
26 int i,
j, lb, ub, stride, nthreads, chunk;
28 int counted_iters = 0;
31 fprintf(stderr,
"error: incorrect number of arguments\n");
32 fprintf(stderr,
"usage: %s <lb> <ub> <stride> <chunk>\n", argv[0]);
37 stride = atoi(argv[3]);
38 chunk = atoi(argv[4]);
41 fprintf(stderr,
"error: lb must be less than ub\n");
45 fprintf(stderr,
"error: stride must be positive integer\n");
49 fprintf(stderr,
"error: chunk must be positive integer\n");
52 for (
i = lb;
i < ub;
i += stride)
55 int *iters = (
int *)malloc(
sizeof(
int) * nthreads * num_iters);
57 int *final_iters = (
int *)malloc(
sizeof(
int) * nthreads * num_iters);
58 for (
i = 0;
i < nthreads * num_iters; ++
i) {
63 #pragma omp parallel num_threads(nthreads)
66 int *my_iters = iters + omp_get_thread_num() * num_iters;
67 #pragma omp for schedule(static, chunk)
68 for (
i = lb;
i < ub;
i += stride) {
76 for (
i = 0,
j = 0;
i < nthreads * num_iters; ++
i) {
78 final_iters[
j++] = iters[
i];
80 if (
j != counted_iters) {
81 fprintf(stderr,
"error: wrong number of final iterations counted!\n");
87 if (counted_iters != num_iters) {
88 fprintf(stderr,
"error: wrong number of iterations executed. Expected %d "
90 num_iters, counted_iters);
95 for (
i = 0;
i < num_iters; ++
i)
96 printf(
"final_iters[%d] = %d\n",
i, final_iters[
i]);
100 for (
i = lb,
j = 0;
i < ub;
i += stride, ++
j) {
101 if (final_iters[
j] !=
i) {
103 "error: iteration j=%d i=%d is incorrect. Expect %d but see %d\n",
104 j,
i,
i, final_iters[
j]);
int compare_ints(const void *v1, const void *v2)
int omp_get_max_threads()