Skip to content
Snippets Groups Projects
Verified Commit 0cabcc80 authored by raphael.bach's avatar raphael.bach
Browse files

Update `array_sum` example

parent ca7fe9de
No related branches found
No related tags found
No related merge requests found
entry array_sum (xs: []i64) : i64 = i64.sum xs
entry self (xs: i64) : i64 = xs
......@@ -8,43 +8,36 @@
// Internal
#include "as.h"
#define LENGTH_X 8
#define LENGTH_Y 8
#define LENGTH_Z 1
#define ARRAY_LENGTH (LENGTH_X) * (LENGTH_Y) * (LENGTH_Z)
#define T int64_t
FMPI_TASK_FUTHARK_SYNC(array_sum, 1)
FMPI_TASK_FUTHARK(array_sum, 1)
int main(int argc, char * argv[])
{
struct fmpi_ctx * ctx = fmpi_init(&argc, &argv);
if(ctx == NULL) {
fprintf(stderr, "fmpi_init() failed!\n");
fmpi_abort();
return EXIT_FAILURE;
}
T in[64] = {
17,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
17,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
17,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
17,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
T in[] = {
1,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,1,
2,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,2,
3,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,3,
4,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,4
};
T out;
const size_t in_size = sizeof(in)/sizeof(T);
T out = -1;
struct fmpi_task array_sum_task = FMPI_TASK_REGISTER(
ctx, array_sum,
ctx, array_sum, fmpi_no_stencil(),
fmpi_data_1d_out(ctx, &out, 1),
fmpi_data_1d_in_new(ctx, in, 64)
fmpi_data_1d_in(ctx, in, in_size)
);
fmpi_task_run(ctx, &array_sum_task);
if(fmpi_is_root(ctx)) {
printf("sum=%ld\n", *(T*)array_sum_task.args.out.start);
printf("sum=%ld\n", out);
}
fmpi_task_run_sync(ctx, &array_sum_task);
printf("rank=%d sum=%ld\n", fmpi_world_rank(ctx), out);
fmpi_exit(&ctx);
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment