Skip to content

Commit

Permalink
Added makefile for multi-core compiling if make is available, happy n…
Browse files Browse the repository at this point in the history
…ew year!
  • Loading branch information
ProjectPhysX committed Dec 31, 2023
1 parent 1bd1fad commit 7fa4ea2
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bin/
temp/
stl/
.vs/
FluidX3D.vcxproj.user
6 changes: 3 additions & 3 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ git clone https://github.com/ProjectPhysX/FluidX3D.git
./make.sh
```
- Compiling requires `C++17`, which is supported since `g++` version `8`. Check with `g++ --version`.
- If you use [`INTERACTIVE_GRAPHICS`](src/defines.hpp), change to the "[compile on Linux with X11](make.sh#L6)" command in [`make.sh`](make.sh#L6).
- If you use [`INTERACTIVE_GRAPHICS`](src/defines.hpp), change to the "[compile on Linux with X11 graphics](make.sh#L3)" command in [`make.sh`](make.sh#L3).
- To select a specific GPU, enter `./make.sh 0` to compile+run, or `bin/FluidX3D 0` to run on device `0`. You can also select multiple GPUs with `bin/FluidX3D 0 1 3 6` if the setup is [configured as multi-GPU](#the-lbm-class).

### macOS
- Select the "[compile on macOS](make.sh#L9)" command in [`make.sh`](make.sh#L9).
- Select the "[compile on macOS](make.sh#L5)" command in [`make.sh`](make.sh#L5).
- Compile and run with:
```bash
chmod +x make.sh
./make.sh
```

### Android
- Select the "[compile on Android](make.sh#L10)" command in [`make.sh`](make.sh#L10).
- Select the "[compile on Android](make.sh#L6)" command in [`make.sh`](make.sh#L6).
- Compile and run with:
```bash
chmod +x make.sh
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2022-2023 Dr. Moritz Lehmann
Copyright (c) 2022-2024 Dr. Moritz Lehmann

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files, to use this software for public research, education or personal use, and to alter it and redistribute it freely, subject to the following restrictions:

Expand Down
23 changes: 15 additions & 8 deletions make.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# command line argument(s): device ID(s); if empty, FluidX3D will automatically choose the fastest available device(s)

mkdir -p bin # create directory for executable
rm -f ./bin/FluidX3D # prevent execution of old version if compiling fails
#TARGET=Linux-X11 # compile on Linux with X11 graphics
TARGET=Linux # compile on Linux (without X11)
#TARGET=macOS # compile on macOS (without X11)
#TARGET=Android # compile on Android (without X11)

#g++ ./src/*.cpp -o ./bin/FluidX3D -std=c++17 -pthread -I./src/OpenCL/include -L./src/OpenCL/lib -lOpenCL -I./src/X11/include -L./src/X11/lib -lX11 # compile on Linux with X11
if command -v make &>/dev/null; then # if make is available, compile FluidX3D with multiple CPU cores
make $TARGET
else # else (make is not installed), compile FluidX3D with a single CPU core
mkdir -p bin # create directory for executable
rm -rf temp bin/FluidX3D # prevent execution of old executable if compiling fails
if [ $TARGET == Linux-X11 ]; then g++ src/*.cpp -o bin/FluidX3D -std=c++17 -pthread -I./src/OpenCL/include -L./src/OpenCL/lib -lOpenCL -I./src/X11/include -L./src/X11/lib -lX11; fi
if [ $TARGET == Linux ]; then g++ src/*.cpp -o bin/FluidX3D -std=c++17 -pthread -I./src/OpenCL/include -L./src/OpenCL/lib -lOpenCL; fi
if [ $TARGET == macOS ]; then g++ src/*.cpp -o bin/FluidX3D -std=c++17 -pthread -I./src/OpenCL/include -framework OpenCL; fi
if [ $TARGET == Android ]; then g++ src/*.cpp -o bin/FluidX3D -std=c++17 -pthread -I./src/OpenCL/include -L/system/vendor/lib64 -lOpenCL; fi
fi

g++ ./src/*.cpp -o ./bin/FluidX3D -std=c++17 -pthread -I./src/OpenCL/include -L./src/OpenCL/lib -lOpenCL # compile on Linux (without X11)
#g++ ./src/*.cpp -o ./bin/FluidX3D -std=c++17 -pthread -I./src/OpenCL/include -framework OpenCL # compile on macOS (without X11)
#g++ ./src/*.cpp -o ./bin/FluidX3D -std=c++17 -pthread -I./src/OpenCL/include -L/system/vendor/lib64 -lOpenCL # compile on Android (without X11)

./bin/FluidX3D "$@" # run FluidX3D
bin/FluidX3D "$@" # run FluidX3D
52 changes: 52 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
MAKEFLAGS = -j$(nproc)
CC = g++
CFLAGS = -std=c++17 -pthread

Linux-X11 Linux: LDFLAGS_OPENCL = -I./src/OpenCL/include -L./src/OpenCL/lib -lOpenCL
macOS: LDFLAGS_OPENCL = -I./src/OpenCL/include -framework OpenCL
Android: LDFLAGS_OPENCL = -I./src/OpenCL/include -L/system/vendor/lib64 -lOpenCL

Linux-X11: LDFLAGS_X11 = -I./src/X11/include -L./src/X11/lib -lX11
Linux macOS Android: LDFLAGS_X11 =

Linux-X11 Linux macOS Android: bin/FluidX3D

bin/FluidX3D: temp/graphics.o temp/info.o temp/kernel.o temp/lbm.o temp/lodepng.o temp/main.o temp/setup.o temp/shapes.o make.sh
@mkdir -p bin
$(CC) temp/*.o -o bin/FluidX3D $(CFLAGS) $(LDFLAGS_OPENCL) $(LDFLAGS_X11)

temp/graphics.o: src/graphics.cpp src/defines.hpp src/graphics.hpp src/lodepng.hpp src/utilities.hpp make.sh
@mkdir -p temp
$(CC) -c src/graphics.cpp -o temp/graphics.o $(CFLAGS) $(LDFLAGS_X11)

temp/info.o: src/info.cpp src/defines.hpp src/graphics.hpp src/info.hpp src/lbm.hpp src/lodepng.hpp src/opencl.hpp src/units.hpp src/utilities.hpp make.sh
@mkdir -p temp
$(CC) -c src/info.cpp -o temp/info.o $(CFLAGS) $(LDFLAGS_OPENCL)

temp/kernel.o: src/kernel.cpp src/kernel.hpp src/lodepng.hpp src/utilities.hpp
@mkdir -p temp
$(CC) -c src/kernel.cpp -o temp/kernel.o $(CFLAGS)

temp/lbm.o: src/lbm.cpp src/defines.hpp src/graphics.hpp src/info.hpp src/lbm.hpp src/lodepng.hpp src/opencl.hpp src/units.hpp src/utilities.hpp make.sh
@mkdir -p temp
$(CC) -c src/lbm.cpp -o temp/lbm.o $(CFLAGS) $(LDFLAGS_OPENCL)

temp/lodepng.o: src/lodepng.cpp src/lodepng.hpp
@mkdir -p temp
$(CC) -c src/lodepng.cpp -o temp/lodepng.o $(CFLAGS)

temp/main.o: src/main.cpp src/defines.hpp src/graphics.hpp src/info.hpp src/lbm.hpp src/lodepng.hpp src/opencl.hpp src/setup.hpp src/shapes.hpp src/units.hpp src/utilities.hpp make.sh
@mkdir -p temp
$(CC) -c src/main.cpp -o temp/main.o $(CFLAGS) $(LDFLAGS_OPENCL)

temp/setup.o: src/setup.cpp src/defines.hpp src/graphics.hpp src/info.hpp src/lbm.hpp src/lodepng.hpp src/opencl.hpp src/setup.hpp src/shapes.hpp src/units.hpp src/utilities.hpp make.sh
@mkdir -p temp
$(CC) -c src/setup.cpp -o temp/setup.o $(CFLAGS) $(LDFLAGS_OPENCL)

temp/shapes.o: src/shapes.cpp src/defines.hpp src/graphics.hpp src/info.hpp src/lbm.hpp src/lodepng.hpp src/opencl.hpp src/shapes.hpp src/units.hpp src/utilities.hpp make.sh
@mkdir -p temp
$(CC) -c src/shapes.cpp -o temp/shapes.o $(CFLAGS) $(LDFLAGS_OPENCL)

.PHONY: clean
clean:
@rm -rf temp bin/FluidX3D
1 change: 0 additions & 1 deletion src/shapes.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include "defines.hpp"
#include "utilities.hpp"

bool sphere(const uint x, const uint y, const uint z, const float3& p, const float r);
Expand Down

0 comments on commit 7fa4ea2

Please sign in to comment.