|
|
## Examples
|
|
|
|
|
|
The examples can be downloaded [here](http://ppmcore.mpi-cbg.de/upload/examples.tar.bz2)
|
|
|
|
|
|
In order to compile the examples, go into your OpenFPM installation root folder and copy the file
|
|
|
|
|
|
```bash
|
|
|
openfpm_pdata/include/example.mk
|
|
|
```
|
|
|
|
|
|
in the root folder (where you decompress the tar.gz) of the examples. To compile the examples do
|
|
|
|
|
|
```bash
|
|
|
make
|
|
|
```
|
|
|
|
|
|
The examples are grouped by data structure, each folder has a set of examples, the number is progressive based on level of complexity. The Makefile inside each example is simple to follow and can be used as a starting point to create your own makefile
|
|
|
|
|
|
## Makefile
|
|
|
|
|
|
OpenFPM installation process generate automatically the file example.mk that file contain include paths information, library path information and linking libraries required in order to compile any project that
|
|
|
use OpenFPM
|
|
|
|
|
|
```makefile
|
|
|
INCLUDE_PATH=-I. -I/usr/local/openfpm_pdata/include/config -I/usr/local/openfpm_pdata/include -I/usr/local/openfpm_data/include -I/usr/local/openfpm_vcluster/include -I/usr/local/openfpm_io/include -I/usr/local/openfpm_devices/include -I/home/i-bird/METIS/include
|
|
|
LIBS_PATH=-L/usr/local/openfpm_devices/lib -L/usr/local/openfpm_vcluster/lib -L/home/i-bird/METIS/lib
|
|
|
LIBS=-lvcluster -lofpmmemory -lmetis -lboost_iostreams
|
|
|
```
|
|
|
|
|
|
Define this a simple Makefile is
|
|
|
|
|
|
|
|
|
```makefile
|
|
|
include ../../example.mk
|
|
|
|
|
|
CC=mpic++
|
|
|
|
|
|
OBJ = main.o
|
|
|
|
|
|
%.o: %.cpp
|
|
|
$(CC) -O3 -c --std=c++11 -o $@ $< $(INCLUDE_PATH)
|
|
|
|
|
|
grid: $(OBJ)
|
|
|
$(CC) -o $@ $^ $(CFLAGS) $(LIBS_PATH) $(LIBS)
|
|
|
|
|
|
all: grid
|
|
|
|
|
|
.PHONY: clean all
|
|
|
|
|
|
clean:
|
|
|
rm -f *.o *~ core grid
|
|
|
```
|
|
|
|
|
|
CC=mpic++ define the compiler
|
|
|
OBJ= define the intermediate files that must be created by compilation before linking
|
|
|
( For example if you have a project composed by file.cpp main.cpp client.cpp you use
|
|
|
|
|
|
```makefile
|
|
|
OBJ = file.o main.o client.o
|
|
|
```
|
|
|
|
|
|
The following of the Makefile define rules and dependencies
|
|
|
|
|
|
```makefile
|
|
|
%.o: %.cpp
|
|
|
$(CC) -O3 -c --std=c++11 -o $@ $< $(INCLUDE_PATH)
|
|
|
```
|
|
|
|
|
|
Is a rule that define how to produce a .o file from a .cpp, basically how to compile a .cpp file
|
|
|
|
|
|
```makefile
|
|
|
grid: $(OBJ)
|
|
|
$(CC) -o $@ $^ $(CFLAGS) $(LIBS_PATH) $(LIBS)
|
|
|
```
|
|
|
|
|
|
Is a rule that define a to produece the final executable, basically how to produce the executable from all the produce .o files
|
|
|
|
|
|
```makefile
|
|
|
all: grid
|
|
|
```
|
|
|
|
|
|
Is the default rule when we use the make, this rule call the others in a nested way
|
|
|
The last rule clean, is a way to remove binary and .o files, we remark that the make file is conservative
|
|
|
if it find that the executable is already created Makefile is not going to re-create it
|
|
|
|
|
|
```makefile
|
|
|
clean:
|
|
|
rm -f *.o *~ core grid
|
|
|
```
|
|
|
|
|
|
If we have a rule "clean: " the default behaviour of the make file is to check if a file called clean exist and only in case does not exist issue the command
|
|
|
|
|
|
```makefile
|
|
|
.PHONY: clean all
|
|
|
```
|
|
|
|
|
|
override this functionality specifying that "clean" and "all" are just rules name without underling file |