diff --git a/Makefile b/Makefile index 60e3a0a1d0a143d0e9cd1734e293f2844b405129..c0e74cf883cb7b7572865dbf9ff54f282e08e031 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,27 @@ -.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!" build: @echo "Building pairs package..." python3 setup.py build && python3 setup.py install --user -lj_ns: - @echo "Generating and compiling CPP for Lennard-Jones example..." - python3 examples/lj_func.py +lj_ns_cpu: + @echo "Generating and compiling Lennard-Jones example for CPU..." + 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 -cpu: build lj_ns +cpu: build lj_ns_cpu g++ -o lj_ns lj_ns.cpp -gpu: build lj_ns +gpu: build lj_ns_gpu nvcc -o lj_ns lj_ns.cu clean: @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 diff --git a/examples/lj_func.py b/examples/lj_func.py index 61c8119f8ef5f5f1e92729f7ab4b51ca08e2efa1..2792c07130bcf3fadf8086bb9780775d2b35d0d4 100644 --- a/examples/lj_func.py +++ b/examples/lj_func.py @@ -1,4 +1,5 @@ import pairs +import sys def lj(i, j): @@ -12,6 +13,12 @@ def euler(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 cutoff_radius = 2.5 skin = 0.3 @@ -32,5 +39,10 @@ psim.vtk_output("output/test") psim.compute(lj, cutoff_radius, {'sigma6': sigma6, 'epsilon': epsilon}) psim.compute(euler, symbols={'dt': dt}) 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()