Skip to content
Snippets Groups Projects
Commit e824ff9a authored by Rafael Ravedutti's avatar Rafael Ravedutti
Browse files

Compile both CPU and GPU versions together

parent 02327683
No related branches found
No related tags found
No related merge requests found
.PHONY: all build clean lj_ns .PHONY: all build clean lj_ns_cpu lj_ns_gpu
all: build lj_ns all: build lj_ns_cpu lj_ns_gpu
@echo "Everything was done!" @echo "Everything was done!"
build: build:
@echo "Building pairs package..." @echo "Building pairs package..."
python3 setup.py build && python3 setup.py install --user python3 setup.py build && python3 setup.py install --user
lj_ns: lj_ns_cpu:
@echo "Generating and compiling CPP for Lennard-Jones example..." @echo "Generating and compiling Lennard-Jones example for CPU..."
python3 examples/lj_func.py python3 examples/lj_func.py cpu
lj_ns_gpu:
@echo "Generating and compiling Lennard-Jones example for GPU..."
python3 examples/lj_func.py gpu
# Targets # Targets
cpu: build lj_ns cpu: build lj_ns_cpu
g++ -o lj_ns lj_ns.cpp g++ -o lj_ns lj_ns.cpp
gpu: build lj_ns gpu: build lj_ns_gpu
nvcc -o lj_ns lj_ns.cu nvcc -o lj_ns lj_ns.cu
clean: clean:
@echo "Cleaning..." @echo "Cleaning..."
rm -rf build lj_ns lj_ns.cpp dist pairs.egg-info functions functions.pdf rm -rf build lj_ns lj_ns.cpp lj_ns.cu dist pairs.egg-info functions functions.pdf
import pairs import pairs
import sys
def lj(i, j): def lj(i, j):
...@@ -12,6 +13,12 @@ def euler(i): ...@@ -12,6 +13,12 @@ def euler(i):
position[i] += dt * velocity[i] position[i] += dt * velocity[i]
cmd = sys.argv[0]
target = sys.argv[1] if len(sys.argv[1]) > 1 else "none"
if target != 'cpu' and target != 'gpu':
print(f"Invalid target, use {cmd} <cpu/gpu>")
dt = 0.005 dt = 0.005
cutoff_radius = 2.5 cutoff_radius = 2.5
skin = 0.3 skin = 0.3
...@@ -32,5 +39,10 @@ psim.vtk_output("output/test") ...@@ -32,5 +39,10 @@ psim.vtk_output("output/test")
psim.compute(lj, cutoff_radius, {'sigma6': sigma6, 'epsilon': epsilon}) psim.compute(lj, cutoff_radius, {'sigma6': sigma6, 'epsilon': epsilon})
psim.compute(euler, symbols={'dt': dt}) psim.compute(euler, symbols={'dt': dt})
psim.target(pairs.target_cpu()) psim.target(pairs.target_cpu())
#psim.target(pairs.target_gpu())
if target == 'gpu':
psim.target(pairs.target_gpu())
else:
psim.target(pairs.target_cpu())
psim.generate() psim.generate()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment