Added a test for building an MPI project. Building for the MPI and C API tests is now also disabled by default.

This commit is contained in:
jpekkila
2019-08-05 18:26:12 +03:00
parent b1176a0c06
commit b21d2040da
4 changed files with 70 additions and 1 deletions

View File

@@ -23,7 +23,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
option(BUILD_DEBUG "Builds the program with extensive error checking" OFF)
option(BUILD_STANDALONE "Builds the standalone Astaroth" ON)
option(BUILD_RT_VISUALIZATION "Builds the module for real-time visualization using SDL2" OFF)
option(BUILD_C_API_TEST "Builds a C program to test whether the API is conformant" ON)
option(BUILD_C_API_TEST "Builds a C program to test whether the API is conformant" OFF)
option(BUILD_MPI_TEST "Builds a C program to test whether MPI works" OFF)
option(DOUBLE_PRECISION "Generates double precision code" OFF)
option(MULTIGPU_ENABLED "If enabled, uses all the available GPUs" ON)
option(ALTER_CONF "If enabled, loads astaroth.conf from the build directory" OFF)
@@ -60,3 +61,7 @@ endif ()
if (BUILD_C_API_TEST)
add_subdirectory(src/ctest)
endif ()
if (BUILD_MPI_TEST)
add_subdirectory(src/mpitest)
endif ()

View File

@@ -0,0 +1,12 @@
##############################################
## CMakeLists.txt for the MPI test ##
##############################################
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
find_package(MPI REQUIRED)
add_executable(mpitest main.c)
target_include_directories(mpitest PRIVATE ${MPI_C_INCLUDE_PATH})
target_link_libraries(mpitest PRIVATE ${MPI_C_LIBRARIES} astaroth_core)

1
src/mpitest/README.txt Normal file
View File

@@ -0,0 +1 @@
This directory is used to test MPI with Astaroth.

51
src/mpitest/main.c Normal file
View File

@@ -0,0 +1,51 @@
/*
Copyright (C) 2014-2019, Johannes Pekkilae, Miikka Vaeisalae.
This file is part of Astaroth.
Astaroth is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Astaroth is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Astaroth. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include "astaroth.h"
#include <mpi.h>
int
main(void)
{
MPI_Init(NULL, NULL);
int num_processes, process_id;
MPI_Comm_size(MPI_COMM_WORLD, &num_processes);
MPI_Comm_rank(MPI_COMM_WORLD, &process_id);
char processor_name[MPI_MAX_PROCESSOR_NAME];
int name_len;
MPI_Get_processor_name(processor_name, &name_len);
printf("Processor %s. Process %d of %d.\n", processor_name, process_id, num_processes);
AcMeshInfo info = {
.int_params[AC_nx] = 128,
.int_params[AC_ny] = 64,
.int_params[AC_nz] = 32,
};
acInit(info);
acIntegrate(0.1f);
acQuit();
MPI_Finalize();
return EXIT_SUCCESS;
}