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

Add `array_sum` example

parent ea2e9f06
No related branches found
No related tags found
No related merge requests found
as-debug
as-release
as.c
as.h
as.json
################################################################################
# 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:
entry array_sum (xs: []i64) : i64 = i64.sum xs
entry self (xs: i64) : i64 = xs
// 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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment