Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
fmpi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
raphael.bach
fmpi
Commits
8ef4248c
Verified
Commit
8ef4248c
authored
2 years ago
by
raphael.bach
Browse files
Options
Downloads
Patches
Plain Diff
Add `README.md`
parent
a8c1d996
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
README.md
+145
-0
145 additions, 0 deletions
README.md
with
145 additions
and
0 deletions
README.md
0 → 100644
+
145
−
0
View file @
8ef4248c
# 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
)
.
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment