Move get number of threads logic to RiaMain

This commit is contained in:
Jørgen Herje 2024-03-21 11:02:25 +01:00
parent f498c79f35
commit 4df9eabf9c
4 changed files with 24 additions and 8 deletions

View File

@ -18,6 +18,7 @@
#include "RiaArgumentParser.h"
#include "RiaMainTools.h"
#include "RiaOpenMPTools.h"
#include "RiaPreferences.h"
#ifdef ENABLE_GRPC
@ -139,6 +140,9 @@ int main( int argc, char* argv[] )
RiaApplication::ApplicationStatus status = app->handleArguments( &progOpt );
int numOmpThreads = RiaOpenMPTools::numberOfThreads();
app->showFormattedTextInMessageBoxOrConsole( QString( "OpenMP Num Threads: %1\n" ).arg( numOmpThreads ) );
if ( status == RiaApplication::ApplicationStatus::EXIT_COMPLETED )
{
// Make sure project is closed to avoid assert and crash in destruction of widgets

View File

@ -48,3 +48,22 @@ int RiaOpenMPTools::currentThreadIndex()
return myThread;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RiaOpenMPTools::numberOfThreads()
{
int numberOfThreads = 1;
#ifdef USE_OPENMP
#pragma omp parallel
{
numberOfThreads = omp_get_num_threads();
}
#endif
return numberOfThreads;
}

View File

@ -27,4 +27,5 @@ namespace RiaOpenMPTools
{
int availableThreadCount();
int currentThreadIndex();
int numberOfThreads();
}; // namespace RiaOpenMPTools

View File

@ -37,7 +37,6 @@
#include <grpcpp/grpcpp.h>
#include <QTcpServer>
#include <omp.h>
using grpc::CompletionQueue;
using grpc::Server;
@ -142,13 +141,6 @@ void RiaGrpcServerImpl::initialize()
ServerBuilder builder;
int numOmpThreads = 0;
#pragma omp parallel
{
numOmpThreads = omp_get_num_threads();
}
RiaLogging::info( QString( "OpenMP Num Threads: %1" ).arg( numOmpThreads ) );
// When setting port number to 0, grpc will find and use a valid port number
// The port number is assigned to the m_portNumber variable after calling builder.BuildAndStart()
QString requestedServerAddress = QString( "localhost:%1" ).arg( m_portNumber );