From 329a71d299bf1895b4204e2f4f63f91b13fe6e30 Mon Sep 17 00:00:00 2001 From: jpekkila Date: Thu, 26 Mar 2020 15:02:55 +0200 Subject: [PATCH] Added an example how to run the code with MPI --- samples/mpitest/main.cc | 42 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/samples/mpitest/main.cc b/samples/mpitest/main.cc index abc0303..d84312a 100644 --- a/samples/mpitest/main.cc +++ b/samples/mpitest/main.cc @@ -20,10 +20,50 @@ Running: mpirun -np */ #include "astaroth.h" +#include "astaroth_utils.h" + +#include int main(void) { - acDeviceRunMPITest(); + MPI_Init(NULL, NULL); + int nprocs, pid; + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + MPI_Comm_rank(MPI_COMM_WORLD, &pid); + + // CPU alloc + AcMeshInfo info; + acLoadConfig(AC_DEFAULT_CONFIG, &info); + + AcMesh model, candidate; + if (pid == 0) { + acMeshCreate(info, &model); + acMeshCreate(info, &candidate); + acMeshRandomize(&model); + acMeshRandomize(&candidate); + } + + // GPU alloc & compute + acGridInit(info); + acGridLoadMesh(model, STREAM_DEFAULT); + + acGridIntegrate(STREAM_DEFAULT, FLT_EPSILON); + acGridPeriodicBoundconds(STREAM_DEFAULT); + + acGridStoreMesh(STREAM_DEFAULT, &candidate); + acGridQuit(); + + // Verify + if (pid == 0) { + acModelIntegrateStep(model, FLT_EPSILON); + acMeshApplyPeriodicBounds(&model); + + acVerifyMesh(model, candidate); + acMeshDestroy(&model); + acMeshDestroy(&candidate); + } + + MPI_Finalize(); return EXIT_SUCCESS; }