diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..2dded438d8d2ea6444f0e034fe786dd387f91ea6 --- /dev/null +++ b/README.md @@ -0,0 +1,145 @@ +# fmpi + +[](LICENSE) + +fmpi is an easy-to-use C library to create simple parallel programs from a +sequential code written in a high-level functional language called Futhark. + +## Table of Contents + +- [Quick overview](#quick-overview) +- [Getting Started](#getting-started) + - [Prerequisites](#prerequisites) + - [Installation](#installation) +- [Documentation](#documentation) +- [License](#license) + +## Quick overview + +Game of Life implemented with `fmpi`: + +Sequential code for Game of Life is written in Futhark in a file named `gol.fut` + +```ml +entry gol [y][x] (xs: [y][x]u64): [][]u64 = + let res = tabulate_2d (y) (x) (\i j -> + if(i > 0 && i < (y-1) && j > 0 && j < (x-1)) then + let cnt = + xs[(i-1), (j-1)] + xs[(i-1), j] + xs[(i-1), (j+1)] + + xs[ i , (j-1)] + 0 + xs[ i , (j+1)] + + xs[(i+1), (j-1)] + xs[(i+1), j] + xs[(i+1), (j+1)] + in u64.bool ((cnt == 3) || ((xs[i, j] == 1) && (cnt == 2))) + else xs[i,j] + ) + in res[1:(y-1), 1:(x-1)] +``` + +Futhark function is called inside a C program with the help of `fmpi`. + +```c +#include <stdio.h> +#include <stdlib.h> +#include <fmpi.h> // Header to include to use fmpi +#include "gol.h" // gol.fut => gol.h + +#define STEP_CNT 20 // Number of Game of Life steps +#define X_LEN 8 // Width of `in` +#define Y_LEN 8 // Height of `in` + +// Declare the futhark `gol` function which has 1 input parameter +FMPI_TASK_FUTHARK(gol, 1) + +int main(int argc, char * argv[]) +{ + // fmpi initialization + struct fmpi_ctx * ctx = fmpi_init(&argc, &argv); + // Initial state of the Game of Life simulation + u64 in[] = { + 0,1,0,0,0,0,0,0, + 0,0,1,0,0,0,0,0, + 1,1,1,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,0,0, + 0,0,0,0,0,0,0,0, + }; + // Number of elements in the in `in` array + #define in_size (sizeof(in)/sizeof(T)) + // Array which will contain the result + u64 out[in_size] = {0}; + // Register the `gol` task which has a square stencil of size 1 in each + // direction, a 2D array of size (X_LEN * Y_LEN) output parameter named `out` + // and a 2D array of of size (X_LEN * Y_LEN) output parameter named `in` + struct fmpi_task gol_task = FMPI_REGISTER_SYNC_TASK( + ctx, gol, fmpi_stencil_square(1), + fmpi_data_2d_out(ctx, out, X_LEN, Y_LEN), + fmpi_data_2d_in(ctx, in, X_LEN, Y_LEN) + ); + // The task is run STEP_CNT times + for(size_t i = 0; i < STEP_CNT; i++) { + fmpi_run_task(ctx, &gol_task); + } + // Gather the results on the root node once the task is done + fmpi_task_finalize(ctx, &gol_task, FMPI_TASK_OP_GATHER); + // Final result is printed by the root node + if(fmpi_is_root(ctx)) { + for(size_t i = 0; i < in_size; i++) { + printf("%lu", out[i]); + if((i+1) % X_LEN == 0) { + printf("\n"); + } + } + } + // Exit fmpi and then the program + fmpi_exit(&ctx); + return EXIT_SUCCESS; +} +``` + +## Getting Started + +### Prerequisites + +- A `C11` compliant compiler is needed to compile the code due to the use of +`_Generic` by `fmpi`. +- MPI(e.g., [OpenMPI](https://www.open-mpi.org/), [MPICH](https://www.mpich.org/), [MVAPICH](https://mvapich.cse.ohio-state.edu/)) +- [Futhark](https://futhark-lang.org/) + +### Installation + +[Download](https://githepia.hesge.ch/raphael.bach/fmpi/-/archive/master/fmpi-master.zip) or +clone the repository: + +```console +git clone https://gitedu.hesge.ch/raphael.bach/fmpi.git +``` + +Install the library to the standard default location `/usr/local/include/fmpi`: + +```console +make install +``` + +Or install them to a different path `/my/custom/path/include/fmpi`: + +```console +make install prefix=/my/custom/path +``` + +Add `/usr/local/include/fmpi` or `/my/custom/path/include/fmpi` to your include +paths. + +## Documentation + +Require Doxygen. + +```console +make doc +``` + +Documentation will be available in `doc/doxygen` + +## License + +This project is licensed under the _very_ permissive [BSD Zero Clause License](LICENSE).