Skip to content

Commit

Permalink
mergerd
Browse files Browse the repository at this point in the history
  • Loading branch information
ScSteffen committed Sep 17, 2024
2 parents 3393908 + c06f727 commit 0d31fe2
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ option( BUILD_UNITY "enables unity build for faster compile times" ON )
option( BUILD_CODE_COV "enables compiler option required for code coverage analysis" OFF )
option( BUILD_ML "enables build with tensorflow backend access" OFF )
option( BUILD_MPI "enables build with MPI access" OFF )
add_definitions(-DBUILD_MPI)
#################################################


Expand All @@ -33,6 +32,7 @@ find_package( OpenMP REQUIRED )

message(STATUS "MPI build flag: ${BUILD_MPI}")
if( BUILD_MPI )
add_definitions(-DIMPORT_MPI)
find_package( MPI REQUIRED )
include_directories( ${MPI_INCLUDE_PATH} )
message(STATUS "C++ compiler: ${CMAKE_CXX_COMPILER}")
Expand Down
6 changes: 3 additions & 3 deletions src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* Disclaimer: This class structure was copied and modifed with open source permission from SU2 v7.0.3 https://su2code.github.io/
*/
#ifdef BUILD_MPI
#ifdef IMPORT_MPI
#include <mpi.h>
#endif
#include "common/config.hpp"
Expand Down Expand Up @@ -1207,7 +1207,7 @@ bool Config::TokenizeString( string& str, string& option_name, vector<string>& o

void Config::InitLogger() {
int rank = 0;
#ifdef BUILD_MPI
#ifdef IMPORT_MPI
MPI_Comm_rank( MPI_COMM_WORLD, &rank ); // Initialize MPI
#endif

Expand Down Expand Up @@ -1366,7 +1366,7 @@ void Config::InitLogger() {
spdlog::flush_every( std::chrono::seconds( 5 ) );
}
}
#ifdef BUILD_MPI
#ifdef IMPORT_MPI
MPI_Barrier( MPI_COMM_WORLD );
#endif
}
Expand Down
8 changes: 4 additions & 4 deletions src/common/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <iomanip>
#include <iostream>

#ifdef BUILD_MPI
#ifdef IMPORT_MPI
#include <mpi.h>
#endif

Expand Down Expand Up @@ -51,7 +51,7 @@ void ExportVTK( const std::string fileName,
const Mesh* mesh ) {
int rank = 0;
int nprocs = 1;
#ifdef BUILD_MPI
#ifdef IMPORT_MPI
// Initialize MPI
MPI_Comm_size( MPI_COMM_WORLD, &nprocs );
MPI_Comm_rank( MPI_COMM_WORLD, &rank );
Expand Down Expand Up @@ -469,7 +469,7 @@ std::string ParseArguments( int argc, char* argv[] ) {
void PrintLogHeader( std::string inputFile ) {
int nprocs = 1;
int rank = 0;
#ifdef BUILD_MPI
#ifdef IMPORT_MPI
// Initialize MPI
MPI_Comm_size( MPI_COMM_WORLD, &nprocs );
MPI_Comm_rank( MPI_COMM_WORLD, &rank );
Expand Down Expand Up @@ -509,7 +509,7 @@ void PrintLogHeader( std::string inputFile ) {
}
// log->info( "------------------------------------------------------------------------" );
}
#ifdef BUILD_MPI
#ifdef IMPORT_MPI
MPI_Barrier( MPI_COMM_WORLD );
#endif
}
Expand Down
11 changes: 5 additions & 6 deletions src/common/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <filesystem>
#include <iostream>
#include <map>
#ifdef BUILD_MPI
#ifdef IMPORT_MPI
#include <mpi.h>
#endif
#include <omp.h>
Expand All @@ -28,7 +28,7 @@ Mesh::Mesh( const Config* settings,
}
int nprocs = 1;
int rank = 0;
#ifdef BUILD_MPI
#ifdef IMPORT_MPI
MPI_Comm_size( MPI_COMM_WORLD, &nprocs );
MPI_Comm_rank( MPI_COMM_WORLD, &rank );
#endif
Expand Down Expand Up @@ -95,7 +95,7 @@ Mesh::~Mesh() {}
void Mesh::ComputeConnectivity() {
int nprocs = 1;
int rank = 0;
#ifdef BUILD_MPI
#ifdef IMPORT_MPI
MPI_Comm_size( MPI_COMM_WORLD, &nprocs );
MPI_Comm_rank( MPI_COMM_WORLD, &rank );
#endif
Expand Down Expand Up @@ -577,16 +577,15 @@ double Mesh::GetDistanceToOrigin( unsigned idx_cell ) const {
return sqrt( distance );
}


unsigned Mesh::GetCellOfKoordinate( const double x, const double y ) const {
// Experimental parallel implementation
unsigned koordinate_cell_id = std::numeric_limits<unsigned>::max();
bool found = false;

//#pragma omp parallel for shared( found )
// #pragma omp parallel for shared( found )
for( unsigned idx_cell = 0; idx_cell < _numCells; idx_cell++ ) {
if( IsPointInsideCell( idx_cell, x, y ) ) {
//#pragma omp critical
// #pragma omp critical
{
if( !found ) {
koordinate_cell_id = idx_cell;
Expand Down
10 changes: 5 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @version: 0.1
*/

#ifdef BUILD_MPI
#ifdef IMPORT_MPI
#include <mpi.h>
#endif
#include <omp.h>
Expand All @@ -30,12 +30,12 @@ int main( int argc, char** argv ) {
#else
// wchar_t* program = Py_DecodeLocale( argv[0], NULL );
// Py_SetProgramName( program );
#ifdef BUILD_MPI
#ifdef IMPORT_MPI
MPI_Init( &argc, &argv );
printf( "| KiT-RT compiled with MPI and OpenMP parallelization\n" );
#endif
#ifndef BUILD_MPI
printf( "| KiT-RT compiled with OpenMP, but without MPI parallelization\n" );
#ifndef IMPORT_MPI
printf( "| KiT-RT compiled with OpenMP, but without MPI parallelization\n" );
#endif

std::string filename = ParseArguments( argc, argv );
Expand Down Expand Up @@ -70,7 +70,7 @@ int main( int argc, char** argv ) {
}

delete config;
#ifdef BUILD_MPI
#ifdef IMPORT_MPI
MPI_Finalize();
#endif

Expand Down
22 changes: 11 additions & 11 deletions src/solvers/snsolver_hpc.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifdef BUILD_MPI
#ifdef IMPORT_MPI
#include <mpi.h>
#endif
#include "common/config.hpp"
Expand All @@ -11,12 +11,12 @@
#include "toolboxes/textprocessingtoolbox.hpp"

SNSolverHPC::SNSolverHPC( Config* settings ) {
#ifdef BUILD_MPI
#ifdef IMPORT_MPI
// Initialize MPI
MPI_Comm_size( MPI_COMM_WORLD, &_numProcs );
MPI_Comm_rank( MPI_COMM_WORLD, &_rank );
#endif
#ifndef BUILD_MPI
#ifndef IMPORT_MPI
_numProcs = 1; // default values
_rank = 0;
#endif
Expand Down Expand Up @@ -148,15 +148,15 @@ SNSolverHPC::SNSolverHPC( Config* settings ) {
}
// _mass += _scalarFlux[idx_cell] * _areas[idx_cell];
}
#ifdef BUILD_MPI
#ifdef IMPORT_MPI
MPI_Barrier( MPI_COMM_WORLD );
#endif
SetGhostCells();
if( _rank == 0 ) {
PrepareScreenOutput(); // Screen Output
PrepareHistoryOutput(); // History Output
}
#ifdef BUILD_MPI
#ifdef IMPORT_MPI
MPI_Barrier( MPI_COMM_WORLD );
#endif
delete quad;
Expand Down Expand Up @@ -532,12 +532,12 @@ void SNSolverHPC::FVMUpdate() {
temp_scalarFlux[idx_cell] = localScalarFlux; // set flux
}
// MPI Allreduce: _scalarFlux
#ifdef BUILD_MPI
#ifdef IMPORT_MPI
MPI_Barrier( MPI_COMM_WORLD );
MPI_Allreduce( temp_scalarFlux.data(), _scalarFlux.data(), _nCells, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
MPI_Barrier( MPI_COMM_WORLD );
#endif
#ifndef BUILD_MPI
#ifndef IMPORT_MPI
_scalarFlux = temp_scalarFlux;
#endif
}
Expand Down Expand Up @@ -681,7 +681,7 @@ void SNSolverHPC::IterPostprocessing() {
}
}
// MPI Allreduce
#ifdef BUILD_MPI
#ifdef IMPORT_MPI
double tmp_curScalarOutflow = 0.0;
double tmp_curScalarOutflowPeri1 = 0.0;
double tmp_curScalarOutflowPeri2 = 0.0;
Expand Down Expand Up @@ -757,12 +757,12 @@ void SNSolverHPC::IterPostprocessing() {

// probe values green
ComputeQOIsGreenProbingLine();
#ifdef BUILD_MPI
#ifdef IMPORT_MPI
MPI_Barrier( MPI_COMM_WORLD );
MPI_Allreduce( temp_probingMoments.data(), _probingMoments.data(), 3 * n_probes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
MPI_Barrier( MPI_COMM_WORLD );
#endif
#ifndef BUILD_MPI
#ifndef IMPORT_MPI
for( unsigned idx_probe = 0; idx_probe < n_probes; idx_probe++ ) { // Loop over probing cells
_probingMoments[Idx2D( idx_probe, 0, 3 )] = temp_probingMoments[Idx2D( idx_probe, 0, 3 )];
_probingMoments[Idx2D( idx_probe, 1, 3 )] = temp_probingMoments[Idx2D( idx_probe, 1, 3 )];
Expand Down Expand Up @@ -1149,7 +1149,7 @@ void SNSolverHPC::PrintHistoryOutput( unsigned idx_iter ) {
}
lineToPrint += tmp + ",";
}
tmp = TextProcessingToolbox::DoubleToScientificNotation( _historyOutputFields[_settings->GetNScreenOutput() - 1] );
tmp = TextProcessingToolbox::DoubleToScientificNotation( _historyOutputFields[_settings->GetNHistoryOutput() - 1] );
lineToPrint += tmp; // Last element without comma

if( _settings->GetHistoryOutputFrequency() != 0 && idx_iter % (unsigned)_settings->GetHistoryOutputFrequency() == 0 ) {
Expand Down

0 comments on commit 0d31fe2

Please sign in to comment.