diff --git a/examples/array_sum/.gitignore b/examples/array_sum/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..ed2d507c73ae75076691a5a568e153b1c951970b --- /dev/null +++ b/examples/array_sum/.gitignore @@ -0,0 +1,5 @@ +as-debug +as-release +as.c +as.h +as.json diff --git a/examples/array_sum/Makefile b/examples/array_sum/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..e53c87b53e7d163756d8bc35f1f2b1e8d46876f3 --- /dev/null +++ b/examples/array_sum/Makefile @@ -0,0 +1,69 @@ +################################################################################ +# BUILD TARGETS - MAIN +################################################################################ +.PHONY: all +all: as-$(BUILD_MODE) + +.PHONY: all-debug +all_debug: + $(MAKE) all BUILD_MODE=debug + +.PHONY: all-release +all_release: + $(MAKE) all BUILD_MODE=release + +as-$(BUILD_MODE): main.c as.c as.h + $(CC) $^ -o $@ $(CFLAGS) $(LDFLAGS) $(LDLIBS) + +as.h as.c &: as.fut + futhark c --library $< +################################################################################ +# CLEAN TARGETS +################################################################################ +.PHONY: clean +clean: clean-$(BUILD_MODE) + +.PHONY: clean-all +clean-all: clean-debug clean-release clean-futhark + +.PHONY: clean-debug +clean-debug: + rm -f as-debug + +.PHONY: clean-release +clean-release: + rm -f as-release + +.PHONY: clean-futhark +clean-futhark: + rm -f as.h + rm -f as.c + rm -f as.json +################################################################################ +# REBUILD TARGETS +################################################################################ +.PHONY: rebuild +rebuild: clean all + +.PHONY: rebuild-debug +rebuild_debug: clean-debug all-debug + +.PHONY: rebuild-release +rebuild_release: clean-release all-release +################################################################################ +# RUN TARGETS +################################################################################ +.PHONY: run +run: run-$(BUILD_MODE) + +.PHONY: run-debug +run-debug: export LD_LIBRARY_PATH:=$(LD_LIBRARY_PATH):../../build/debug +run-debug: + mpirun as-debug + +.PHONY: run-release +run-release: export LD_LIBRARY_PATH:=$(LD_LIBRARY_PATH):../../build/release +run-release: + mpirun as-release +################################################################################ +.DELETE_ON_ERROR: diff --git a/examples/array_sum/as.fut b/examples/array_sum/as.fut new file mode 100644 index 0000000000000000000000000000000000000000..2302ebae0926793ecfb19d3664c927027542c41b --- /dev/null +++ b/examples/array_sum/as.fut @@ -0,0 +1,2 @@ +entry array_sum (xs: []i64) : i64 = i64.sum xs +entry self (xs: i64) : i64 = xs diff --git a/examples/array_sum/main.c b/examples/array_sum/main.c new file mode 100644 index 0000000000000000000000000000000000000000..651be51fcfd2c91fae8d51827985cd1524a599cc --- /dev/null +++ b/examples/array_sum/main.c @@ -0,0 +1,53 @@ +// C Standard Library +#include <assert.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +// fmpi +#include <fmpi.h> +// 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(fut_array_sum, futhark_entry_array_sum) + +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(); + } + T in[64] = { + 17,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + 0,0,0,0,0,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,0,0,0,0, + 0,0,0,0,0,0,0,17, + }; + T out = 0; + struct fmpi_data data_in = fmpi_data_1d(in, 64); + struct fmpi_data data_out = fmpi_data_1d(&out, 1); + struct fmpi_task_args array_sum_args = { + .in = {data_in}, + .out = data_out, + .cnt = 1 + }; + struct fmpi_task array_sum_task = fmpi_task_register(ctx, fut_array_sum, &array_sum_args); + 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_exit(&ctx); + return EXIT_SUCCESS; +}