From 071df5c75cf91702b9c22367cdd012ce43f33bdd Mon Sep 17 00:00:00 2001 From: Shintaro Iwasaki Date: Tue, 31 Mar 2020 09:58:58 -0500 Subject: [PATCH 1/5] examples: add fibonacci_recursive The Argobots examples lack the simplest one, which calculates the Fibonacci number in a recursive divide-and-conquer manner. This patch adds it. --- examples/.gitignore | 1 + examples/Makefile.am | 3 + examples/fibonacci_recursive.c | 122 +++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 examples/fibonacci_recursive.c diff --git a/examples/.gitignore b/examples/.gitignore index 6d7db954e..e0698aa83 100644 --- a/examples/.gitignore +++ b/examples/.gitignore @@ -1,5 +1,6 @@ # examples fibonacci_future +fibonacci_recursive fibonacci_task fibonacci_thread_task hello_world diff --git a/examples/Makefile.am b/examples/Makefile.am index 05e9b5b82..560b05020 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -7,6 +7,7 @@ TESTS = \ hello_world \ hello_world_thread \ fibonacci_future \ + fibonacci_recursive \ fibonacci_task \ fibonacci_thread_task \ sched_predef \ @@ -26,6 +27,7 @@ include $(top_srcdir)/test/Makefile.mk hello_world_SOURCES = hello_world.c hello_world_thread_SOURCES = hello_world_thread.c fibonacci_future_SOURCES = fibonacci_future.c +fibonacci_recursive_SOURCES = fibonacci_recursive.c fibonacci_task_SOURCES = fibonacci_task.c fibonacci_thread_task_SOURCES = fibonacci_thread_task.c sched_predef_SOURCES = sched_predef.c @@ -41,6 +43,7 @@ testing: ./hello_world ./hello_world_thread ./fibonacci_future + ./fibonacci_recursive ./fibonacci_task ./fibonacci_thread_task ./sched_predef diff --git a/examples/fibonacci_recursive.c b/examples/fibonacci_recursive.c new file mode 100644 index 000000000..1c167dce0 --- /dev/null +++ b/examples/fibonacci_recursive.c @@ -0,0 +1,122 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * See COPYRIGHT in top-level directory. + */ + +/** + * This Fibonacci example showcases recursive parallelism. + */ + +#include +#include +#include +#include + +#define N 10 +#define NUM_XSTREAMS 4 + +/* global variables */ +ABT_pool g_pool = ABT_POOL_NULL; + +/* structure to pass arguments to threads */ +typedef struct { + int n; + int result; +} thread_args; + +/* Function to compute Fibonacci numbers */ +void fibonacci(void *arguments) +{ + thread_args *args = (thread_args *)arguments; + int n = args->n; + + /* checking for base cases */ + if (n <= 2) + args->result = 1; + else { + thread_args a1, a2; + ABT_thread thread1; + + a1.n = n - 1; + ABT_thread_create(g_pool, fibonacci, &a1, ABT_THREAD_ATTR_NULL, + &thread1); + a2.n = n - 2; + fibonacci(&a2); + + ABT_thread_free(&thread1); + args->result = a1.result + a2.result; + } +} + +/* Verification function */ +int verify(int n) +{ + int i; + int old[2], val; + + if (n <= 2) + return 1; + + old[0] = old[1] = 1; + for (i = 3; i <= n; i++) { + val = old[0] + old[1]; + old[i % 2] = val; + } + return val; +} + +/* Main function */ +int main(int argc, char *argv[]) +{ + int n, i, expected; + int num_xstreams; + ABT_xstream *xstreams; + thread_args args; + + if (argc > 1 && strcmp(argv[1], "-h") == 0) { + printf("Usage: %s [N=10] [num_ES=4]\n", argv[0]); + return EXIT_SUCCESS; + } + n = argc > 1 ? atoi(argv[1]) : N; + num_xstreams = argc > 2 ? atoi(argv[2]) : NUM_XSTREAMS; + printf("# of ESs: %d\n", num_xstreams); + + /* initialization */ + ABT_init(argc, argv); + + /* shared pool creation */ + ABT_pool_create_basic(ABT_POOL_FIFO, ABT_POOL_ACCESS_MPMC, ABT_TRUE, + &g_pool); + + /* ES creation */ + xstreams = (ABT_xstream *)malloc(sizeof(ABT_xstream) * num_xstreams); + ABT_xstream_self(&xstreams[0]); + ABT_xstream_set_main_sched_basic(xstreams[0], ABT_SCHED_DEFAULT, 1, + &g_pool); + for (i = 1; i < num_xstreams; i++) { + ABT_xstream_create_basic(ABT_SCHED_DEFAULT, 1, &g_pool, + ABT_SCHED_CONFIG_NULL, &xstreams[i]); + } + + args.n = n; + fibonacci(&args); + + /* join ESs */ + for (i = 1; i < num_xstreams; i++) { + ABT_xstream_join(xstreams[i]); + ABT_xstream_free(&xstreams[i]); + } + + ABT_finalize(); + + free(xstreams); + + printf("Fib(%d): %d\n", n, args.result); + expected = verify(n); + if (args.result != expected) { + fprintf(stderr, "ERROR: expected=%d\n", expected); + exit(EXIT_FAILURE); + } + + return EXIT_SUCCESS; +} From b6da6829bf6fb80821998113e810c65d4f3ab931 Mon Sep 17 00:00:00 2001 From: Shintaro Iwasaki Date: Tue, 31 Mar 2020 10:01:44 -0500 Subject: [PATCH 2/5] examples: remove fibonacci_task and fibonacci_thread_task In fibonacci_task and fibonacci_thread_task, tasklets call blocking functions, which are prohibited. These tests should be removed. --- examples/.gitignore | 2 - examples/Makefile.am | 6 - examples/fibonacci_task.c | 230 ------------------------------ examples/fibonacci_thread_task.c | 233 ------------------------------- 4 files changed, 471 deletions(-) delete mode 100644 examples/fibonacci_task.c delete mode 100644 examples/fibonacci_thread_task.c diff --git a/examples/.gitignore b/examples/.gitignore index e0698aa83..c1ff50b53 100644 --- a/examples/.gitignore +++ b/examples/.gitignore @@ -1,8 +1,6 @@ # examples fibonacci_future fibonacci_recursive -fibonacci_task -fibonacci_thread_task hello_world hello_world_thread sched_predef diff --git a/examples/Makefile.am b/examples/Makefile.am index 560b05020..d9a05c880 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -8,8 +8,6 @@ TESTS = \ hello_world_thread \ fibonacci_future \ fibonacci_recursive \ - fibonacci_task \ - fibonacci_thread_task \ sched_predef \ sched_shared_pool \ sched_stack \ @@ -28,8 +26,6 @@ hello_world_SOURCES = hello_world.c hello_world_thread_SOURCES = hello_world_thread.c fibonacci_future_SOURCES = fibonacci_future.c fibonacci_recursive_SOURCES = fibonacci_recursive.c -fibonacci_task_SOURCES = fibonacci_task.c -fibonacci_thread_task_SOURCES = fibonacci_thread_task.c sched_predef_SOURCES = sched_predef.c sched_shared_pool_SOURCES = sched_shared_pool.c sched_stack_SOURCES = sched_stack.c @@ -44,8 +40,6 @@ testing: ./hello_world_thread ./fibonacci_future ./fibonacci_recursive - ./fibonacci_task - ./fibonacci_thread_task ./sched_predef ./sched_shared_pool ./sched_stack diff --git a/examples/fibonacci_task.c b/examples/fibonacci_task.c deleted file mode 100644 index 46165ca0a..000000000 --- a/examples/fibonacci_task.c +++ /dev/null @@ -1,230 +0,0 @@ -/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ -/* - * See COPYRIGHT in top-level directory. - */ - -/** - * This example shows the use of tasks to compute Fibonacci numbers. The - * execution proceeds in two phases. 1) Expand phase. A binary tree of - * activation records is built in a top-down fashion. Each activation record - * corresponds to a Fibonacci number Fib(n) computed recursively. A task - * computing Fib(n) will create two subtasks to compute Fib(n-1) and Fib(n-2), - * respectively. 2) Aggregrate phase. The final results is computed bottom-up. - * Once a base case is reached (n<=2), a task is created to aggregate the result - * into the parent's activation record. Therefore, two tasks will update the - * activation record for Fib(n). The last of the two aggregate tasks will spawn - * another task that will aggregate the result up the binary tree. - */ - -#include -#include -#include -#include - -#define N 10 -#define NUM_XSTREAMS 4 - -/* global variables */ -ABT_pool g_pool = ABT_POOL_NULL; -ABT_eventual eventual = ABT_EVENTUAL_NULL; - -/* forward declaration */ -void aggregate_fibonacci(void *arguments); - -/* structure to pass arguments to expand tasks */ -typedef struct exp_task_args_t { - int n; - int result; - int flag; - ABT_mutex mutex; - struct exp_task_args_t *parent; -} exp_task_args; - -/* structure to pass arguments to aggregate tasks */ -typedef struct agg_task_args_t { - int result; - exp_task_args *parent; -} agg_task_args; - -/* Function to compute Fibonacci numbers during expand phase */ -void expand_fibonacci(void *arguments) -{ - int n; - exp_task_args *exp_args1, *exp_args2, *parent; - agg_task_args *agg_args; - - exp_task_args *args = (exp_task_args *)arguments; - n = args->n; - parent = args->parent; - - /* checking for base cases */ - if (n <= 2) { - /* creating an aggregate task */ - if (parent != NULL) { - agg_args = (agg_task_args *)malloc(sizeof(agg_task_args)); - agg_args->result = 1; - agg_args->parent = parent; - ABT_task_create(g_pool, aggregate_fibonacci, agg_args, NULL); - } else { - args->result = 1; - ABT_eventual_set(eventual, &args->result, sizeof(int)); - } - ABT_mutex_free(&args->mutex); - free(args); - } else { - /* creating task to compute Fib(n-1) */ - exp_args1 = (exp_task_args *)malloc(sizeof(exp_task_args)); - exp_args1->n = n - 1; - exp_args1->result = 0; - exp_args1->flag = 0; - ABT_mutex_create(&exp_args1->mutex); - exp_args1->parent = args; - ABT_task_create(g_pool, expand_fibonacci, exp_args1, NULL); - - /* creating task to compute Fib(n-2) */ - exp_args2 = (exp_task_args *)malloc(sizeof(exp_task_args)); - exp_args2->n = n - 2; - exp_args2->result = 0; - exp_args2->flag = 0; - ABT_mutex_create(&exp_args2->mutex); - exp_args2->parent = args; - ABT_task_create(g_pool, expand_fibonacci, exp_args2, NULL); - } -} - -/* Function to compute Fibonacci numbers during aggregate phase */ -void aggregate_fibonacci(void *arguments) -{ - exp_task_args *parent; - agg_task_args *args, *agg_args; - int result; - - args = (agg_task_args *)arguments; - parent = args->parent; - result = args->result; - free(args); - - /* checking whether this is the root of the tree */ - if (parent != NULL) { - int flag; - ABT_mutex_lock(parent->mutex); - parent->result += result; - flag = parent->flag; - if (!flag) - parent->flag = 1; - ABT_mutex_unlock(parent->mutex); - if (flag) { - /* creating an aggregate task */ - agg_args = (agg_task_args *)malloc(sizeof(agg_task_args)); - agg_args->result = parent->result; - agg_args->parent = parent->parent; - ABT_task_create(g_pool, aggregate_fibonacci, agg_args, NULL); - - ABT_mutex_free(&parent->mutex); - free(parent); - } - } else { - ABT_eventual_set(eventual, &result, sizeof(int)); - } -} - -int fibonacci(int n) -{ - exp_task_args *args; - int result; - int *data; - - /* creating eventual */ - ABT_eventual_create(sizeof(int), &eventual); - - /* creating parent task to compute Fib(n) */ - args = (exp_task_args *)malloc(sizeof(exp_task_args)); - args->n = n; - args->result = 0; - args->flag = 0; - ABT_mutex_create(&args->mutex); - args->parent = NULL; - ABT_task_create(g_pool, expand_fibonacci, args, NULL); - - /* block until the eventual is signaled */ - ABT_eventual_wait(eventual, (void **)&data); - - /* get the result */ - result = *data; - - ABT_eventual_free(&eventual); - - return result; -} - -/* Verification function */ -int verify(int n) -{ - int i; - int old[2], val; - - if (n <= 2) - return 1; - - old[0] = old[1] = 1; - for (i = 3; i <= n; i++) { - val = old[0] + old[1]; - old[i % 2] = val; - } - return val; -} - -/* Main function */ -int main(int argc, char *argv[]) -{ - int n, i, result, expected; - int num_xstreams; - ABT_xstream *xstreams; - - if (argc > 1 && strcmp(argv[1], "-h") == 0) { - printf("Usage: %s [N=10] [num_ES=4]\n", argv[0]); - return EXIT_SUCCESS; - } - n = argc > 1 ? atoi(argv[1]) : N; - num_xstreams = argc > 2 ? atoi(argv[2]) : NUM_XSTREAMS; - printf("# of ESs: %d\n", num_xstreams); - - /* initialization */ - ABT_init(argc, argv); - - /* shared pool creation */ - ABT_pool_create_basic(ABT_POOL_FIFO, ABT_POOL_ACCESS_MPMC, ABT_TRUE, - &g_pool); - - /* ES creation */ - xstreams = (ABT_xstream *)malloc(sizeof(ABT_xstream) * num_xstreams); - ABT_xstream_self(&xstreams[0]); - ABT_xstream_set_main_sched_basic(xstreams[0], ABT_SCHED_DEFAULT, 1, - &g_pool); - for (i = 1; i < num_xstreams; i++) { - ABT_xstream_create_basic(ABT_SCHED_DEFAULT, 1, &g_pool, - ABT_SCHED_CONFIG_NULL, &xstreams[i]); - ABT_xstream_start(xstreams[i]); - } - - result = fibonacci(n); - - /* join ESs */ - for (i = 1; i < num_xstreams; i++) { - ABT_xstream_join(xstreams[i]); - ABT_xstream_free(&xstreams[i]); - } - - ABT_finalize(); - - free(xstreams); - - printf("Fib(%d): %d\n", n, result); - expected = verify(n); - if (result != expected) { - fprintf(stderr, "ERROR: expected=%d\n", expected); - exit(EXIT_FAILURE); - } - - return EXIT_SUCCESS; -} diff --git a/examples/fibonacci_thread_task.c b/examples/fibonacci_thread_task.c deleted file mode 100644 index 7b6a0216c..000000000 --- a/examples/fibonacci_thread_task.c +++ /dev/null @@ -1,233 +0,0 @@ -/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ -/* - * See COPYRIGHT in top-level directory. - */ - -/** - * This example shows the interleaving of threads and tasks to compute Fibonacci - * numbers. - */ - -#include -#include -#include -#include - -#define N 10 -#define NUM_XSTREAMS 4 - -/* global variables */ -ABT_pool g_pool = ABT_POOL_NULL; - -/* structure to pass arguments to threads */ -typedef struct { - int n; - int result; - ABT_eventual eventual; -} thread_args; - -/* structure to pass arguments to threads */ -typedef struct task_args_t { - int n; - int result; - ABT_mutex mutex; - struct task_args_t *parent; -} task_args; - -/* Function to compute Fibonacci numbers */ -void fibonacci_thread(void *arguments) -{ - int n, *n1, *n2; - thread_args a1, a2; - ABT_eventual eventual, f1, f2; - - thread_args *args = (thread_args *)arguments; - n = args->n; - eventual = args->eventual; - - /* checking for base cases */ - if (n <= 2) - args->result = 1; - else { - ABT_eventual_create(sizeof(int), &f1); - a1.n = n - 1; - a1.eventual = f1; - ABT_thread_create(g_pool, fibonacci_thread, &a1, ABT_THREAD_ATTR_NULL, - NULL); - - ABT_eventual_create(sizeof(int), &f2); - a2.n = n - 2; - a2.eventual = f2; - ABT_thread_create(g_pool, fibonacci_thread, &a2, ABT_THREAD_ATTR_NULL, - NULL); - - ABT_eventual_wait(f1, (void **)&n1); - ABT_eventual_wait(f2, (void **)&n2); - - args->result = *n1 + *n2; - - ABT_eventual_free(&f1); - ABT_eventual_free(&f2); - } - - /* checking whether to signal the eventual */ - if (eventual != ABT_EVENTUAL_NULL) { - ABT_eventual_set(eventual, &args->result, sizeof(int)); - } -} - -/* Function to compute Fibonacci numbers */ -void fibonacci_task(void *arguments) -{ - int n, result; - task_args *a1, *a2, *parent, *temp; - ABT_task t1, t2; - - task_args *args = (task_args *)arguments; - n = args->n; - parent = args->parent; - - /* checking for base cases */ - if (n <= 2) { - args->result = 1; - result = 1; - int flag = 1; - while (flag && parent != NULL) { - ABT_mutex_lock(parent->mutex); - parent->result += result; - if (result == parent->result) - flag = 0; - ABT_mutex_unlock(parent->mutex); - result = parent->result; - temp = parent->parent; - - if (flag && temp) { - ABT_mutex_free(&parent->mutex); - free(parent); - } - - parent = temp; - } - - ABT_mutex_free(&args->mutex); - if (args->parent) { - free(args); - } - } else { - a1 = (task_args *)malloc(sizeof(task_args)); - a1->n = n - 1; - a1->result = 0; - ABT_mutex_create(&a1->mutex); - a1->parent = args; - ABT_task_create(g_pool, fibonacci_task, a1, &t1); - - a2 = (task_args *)malloc(sizeof(task_args)); - a2->n = n - 2; - a2->result = 0; - ABT_mutex_create(&a2->mutex); - a2->parent = args; - ABT_task_create(g_pool, fibonacci_task, a2, &t2); - } -} - -/* Verification function */ -int verify(int n) -{ - int i; - int old[2], val; - - if (n <= 2) - return 1; - - old[0] = old[1] = 1; - for (i = 3; i <= n; i++) { - val = old[0] + old[1]; - old[i % 2] = val; - } - return val; -} - -/* Main function */ -int main(int argc, char *argv[]) -{ - int n, i, result, expected; - int num_xstreams; - ABT_xstream *xstreams; - - ABT_thread thread; - thread_args args_thread; - ABT_task task; - task_args *args_task; - - if (argc > 1 && strcmp(argv[1], "-h") == 0) { - printf("Usage: %s [N=10] [num_ES=4]\n", argv[0]); - return EXIT_SUCCESS; - } - n = argc > 1 ? atoi(argv[1]) : N; - num_xstreams = argc > 2 ? atoi(argv[2]) : NUM_XSTREAMS; - printf("# of ESs: %d\n", num_xstreams); - - if (n <= 2) { - result = 1; - goto fn_result; - } - - /* initialization */ - ABT_init(argc, argv); - - /* shared pool creation */ - ABT_pool_create_basic(ABT_POOL_FIFO, ABT_POOL_ACCESS_MPMC, ABT_TRUE, - &g_pool); - - /* ES creation */ - xstreams = (ABT_xstream *)malloc(sizeof(ABT_xstream) * num_xstreams); - ABT_xstream_self(&xstreams[0]); - ABT_xstream_set_main_sched_basic(xstreams[0], ABT_SCHED_DEFAULT, 1, - &g_pool); - for (i = 1; i < num_xstreams; i++) { - ABT_xstream_create_basic(ABT_SCHED_DEFAULT, 1, &g_pool, - ABT_SCHED_CONFIG_NULL, &xstreams[i]); - ABT_xstream_start(xstreams[i]); - } - - /* creating thread */ - args_thread.n = n - 1; - args_thread.eventual = ABT_EVENTUAL_NULL; - ABT_thread_create(g_pool, fibonacci_thread, &args_thread, - ABT_THREAD_ATTR_NULL, &thread); - - /* creating task */ - args_task = (task_args *)malloc(sizeof(task_args)); - args_task->n = n - 2; - args_task->result = 0; - ABT_mutex_create(&args_task->mutex); - args_task->parent = NULL; - ABT_task_create(g_pool, fibonacci_task, args_task, &task); - - /* join other threads */ - ABT_thread_join(thread); - ABT_thread_free(&thread); - - /* join ESs */ - for (i = 1; i < num_xstreams; i++) { - ABT_xstream_join(xstreams[i]); - ABT_xstream_free(&xstreams[i]); - } - - result = args_thread.result + args_task->result; - free(args_task); - - ABT_finalize(); - - free(xstreams); - -fn_result: - printf("Fib(%d): %d\n", n, result); - expected = verify(n); - if (result != expected) { - fprintf(stderr, "ERROR: expected=%d\n", expected); - exit(EXIT_FAILURE); - } - - return EXIT_SUCCESS; -} From 3e9b2ce2964bc89a4bf7006db482058e3a5fd9f4 Mon Sep 17 00:00:00 2001 From: Shintaro Iwasaki Date: Tue, 31 Mar 2020 10:02:02 -0500 Subject: [PATCH 3/5] examples: remove ABT_xstream_start() in fibonacci_future ABT_xstream_start() was deprecated and already removed. --- examples/fibonacci_future.c | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/fibonacci_future.c b/examples/fibonacci_future.c index 4d235a073..6b8536f1b 100644 --- a/examples/fibonacci_future.c +++ b/examples/fibonacci_future.c @@ -120,7 +120,6 @@ int main(int argc, char *argv[]) for (i = 1; i < num_xstreams; i++) { ABT_xstream_create_basic(ABT_SCHED_DEFAULT, 1, &g_pool, ABT_SCHED_CONFIG_NULL, &xstreams[i]); - ABT_xstream_start(xstreams[i]); } args.n = n; From f358351f152244b52db5dff8f6e41fd7572fe9d7 Mon Sep 17 00:00:00 2001 From: Shintaro Iwasaki Date: Tue, 31 Mar 2020 10:03:00 -0500 Subject: [PATCH 4/5] examples: give a name to an unnamed union ISO C99 does not allow an unnamed union. --- examples/sched_and_pool_user.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/sched_and_pool_user.c b/examples/sched_and_pool_user.c index d365556cf..6110d3012 100644 --- a/examples/sched_and_pool_user.c +++ b/examples/sched_and_pool_user.c @@ -244,7 +244,7 @@ struct example_unit { union { ABT_thread thread; ABT_task task; - }; + } handle; ABT_unit_type type; }; @@ -577,7 +577,7 @@ static ABT_thread unit_get_thread(ABT_unit unit) ABT_thread h_thread; unit_t *p_unit = (unit_t *)unit; if (p_unit->type == ABT_UNIT_TYPE_THREAD) { - h_thread = p_unit->thread; + h_thread = p_unit->handle.thread; } else { h_thread = ABT_THREAD_NULL; } @@ -589,7 +589,7 @@ static ABT_task unit_get_task(ABT_unit unit) ABT_task h_task; unit_t *p_unit = (unit_t *)unit; if (p_unit->type == ABT_UNIT_TYPE_TASK) { - h_task = p_unit->task; + h_task = p_unit->handle.task; } else { h_task = ABT_TASK_NULL; } @@ -611,7 +611,7 @@ static ABT_unit unit_create_from_thread(ABT_thread thread) p_unit->p_prev = NULL; p_unit->p_next = NULL; p_unit->pool = ABT_POOL_NULL; - p_unit->thread = thread; + p_unit->handle.thread = thread; p_unit->type = ABT_UNIT_TYPE_THREAD; return (ABT_unit)p_unit; @@ -626,7 +626,7 @@ static ABT_unit unit_create_from_task(ABT_task task) p_unit->p_prev = NULL; p_unit->p_next = NULL; p_unit->pool = ABT_POOL_NULL; - p_unit->task = task; + p_unit->handle.task = task; p_unit->type = ABT_UNIT_TYPE_TASK; return (ABT_unit)p_unit; From 8192312cd16065d3b42ddaf79514f5232ff5ce10 Mon Sep 17 00:00:00 2001 From: Shintaro Iwasaki Date: Tue, 31 Mar 2020 10:09:38 -0500 Subject: [PATCH 5/5] examples: fix the variable shadowing issue in stencil tests --- examples/stencil_task.c | 8 ++++---- examples/stencil_thread.c | 8 ++++---- examples/stencil_thread_cond.c | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/stencil_task.c b/examples/stencil_task.c index 395ec13ea..e9a1e2d69 100644 --- a/examples/stencil_task.c +++ b/examples/stencil_task.c @@ -135,14 +135,14 @@ static int eq(double a, double b) return (a - b < e); } -static int check(double *results, int n) +static int check(double *r, int n) { int i, j; for (i = 0; i < n / 2; i++) { for (j = 0; j < n / 2; j++) { - if (!eq(results[i * n + j], results[i * n + (n - 1 - j)]) || - !eq(results[i * n + j], results[(n - 1 - i) * n + j]) || - !eq(results[i * n + j], results[(n - 1 - i) * n + (n - 1 - j)])) + if (!eq(r[i * n + j], r[i * n + (n - 1 - j)]) || + !eq(r[i * n + j], r[(n - 1 - i) * n + j]) || + !eq(r[i * n + j], r[(n - 1 - i) * n + (n - 1 - j)])) return 0; } } diff --git a/examples/stencil_thread.c b/examples/stencil_thread.c index b0321c6d6..56f94e60d 100644 --- a/examples/stencil_thread.c +++ b/examples/stencil_thread.c @@ -138,14 +138,14 @@ static int eq(double a, double b) return (a - b < e); } -static int check(double *results, int n) +static int check(double *r, int n) { int i, j; for (i = 0; i < n / 2; i++) { for (j = 0; j < n / 2; j++) { - if (!eq(results[i * n + j], results[i * n + (n - 1 - j)]) || - !eq(results[i * n + j], results[(n - 1 - i) * n + j]) || - !eq(results[i * n + j], results[(n - 1 - i) * n + (n - 1 - j)])) + if (!eq(r[i * n + j], r[i * n + (n - 1 - j)]) || + !eq(r[i * n + j], r[(n - 1 - i) * n + j]) || + !eq(r[i * n + j], r[(n - 1 - i) * n + (n - 1 - j)])) return 0; } } diff --git a/examples/stencil_thread_cond.c b/examples/stencil_thread_cond.c index 228a678cf..577484229 100644 --- a/examples/stencil_thread_cond.c +++ b/examples/stencil_thread_cond.c @@ -218,14 +218,14 @@ static int eq(double a, double b) return (a - b < e); } -static int check(double *results, int n) +static int check(double *r, int n) { int i, j; for (i = 0; i < n / 2; i++) { for (j = 0; j < n / 2; j++) { - if (!eq(results[i * n + j], results[i * n + (n - 1 - j)]) || - !eq(results[i * n + j], results[(n - 1 - i) * n + j]) || - !eq(results[i * n + j], results[(n - 1 - i) * n + (n - 1 - j)])) + if (!eq(r[i * n + j], r[i * n + (n - 1 - j)]) || + !eq(r[i * n + j], r[(n - 1 - i) * n + j]) || + !eq(r[i * n + j], r[(n - 1 - i) * n + (n - 1 - j)])) return 0; } }