From 01fb5e19b0cc6f25c64be7bf96fa35676609a4e7 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 2 Jun 2023 11:28:02 +0200 Subject: [PATCH] [EDF27562] : 2 new methods to simulate computation to ease test in charge YACS --- CMakeLists.txt | 2 +- SalomeKERNELConfig.cmake.in | 1 + src/Basics/CMakeLists.txt | 17 +- src/Basics/HeatMarcel.cxx | 162 ++++++++++++++++++ src/Basics/HeatMarcel.hxx | 29 ++++ src/Basics/KernelBasis.i | 19 ++ src/Basics/baseutilities.h | 29 ++++ .../libSALOMELog.cxx | 3 - .../libSALOMELog.hxx | 12 +- src/SALOMELocalTrace/CMakeLists.txt | 5 +- 10 files changed, 256 insertions(+), 23 deletions(-) create mode 100644 src/Basics/HeatMarcel.cxx create mode 100644 src/Basics/HeatMarcel.hxx create mode 100644 src/Basics/baseutilities.h rename src/{SALOMELocalTrace => Basics}/libSALOMELog.cxx (94%) rename src/{SALOMELocalTrace => Basics}/libSALOMELog.hxx (78%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 282f4219e..cbf8b0eb6 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -213,7 +213,7 @@ INCLUDE(CMakePackageConfigHelpers) # They all have to be INSTALL'd with the option "EXPORT ${PROJECT_NAME}TargetGroup" SET(_${PROJECT_NAME}_exposed_targets - SALOMEBasics ArgvKeeper SALOMELocalTrace SalomeHDFPersist OpUtil) + SALOMELog SALOMEBasics ArgvKeeper SALOMELocalTrace SalomeHDFPersist OpUtil) # CORBA specific targets: IF(NOT SALOME_LIGHT_ONLY) diff --git a/SalomeKERNELConfig.cmake.in b/SalomeKERNELConfig.cmake.in index f7a73af3e..8b60a797e 100644 --- a/SalomeKERNELConfig.cmake.in +++ b/SalomeKERNELConfig.cmake.in @@ -159,6 +159,7 @@ SET(KERNEL_NamingServiceTest NamingServiceTest) SET(KERNEL_OpUtil OpUtil) SET(KERNEL_Registry Registry) SET(KERNEL_ResourcesManager ResourcesManager) +SET(KERNEL_SALOMELog SALOMELog) SET(KERNEL_SALOMEBasics SALOMEBasics) SET(KERNEL_SalomeCatalog SalomeCatalog) SET(KERNEL_SalomeCommunication SalomeCommunication) diff --git a/src/Basics/CMakeLists.txt b/src/Basics/CMakeLists.txt index 68fd64810..42c6d07e2 100644 --- a/src/Basics/CMakeLists.txt +++ b/src/Basics/CMakeLists.txt @@ -25,26 +25,31 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} ) +SET(SALOMELog_SOURCES + libSALOMELog.cxx +) + SET(SALOMEBasics_SOURCES BasicsGenericDestructor.cxx Basics_Utils.cxx Basics_DirUtils.cxx - SALOME_Basics.hxx - BasicsGenericDestructor.hxx - Basics_Utils.hxx - Basics_DirUtils.hxx KernelBasis.cxx + HeatMarcel.cxx ) +ADD_LIBRARY(SALOMELog ${SALOMELog_SOURCES}) +TARGET_LINK_LIBRARIES(SALOMELog ${PLATFORM_LIBS} ${PTHREAD_LIBRARIES}) +INSTALL(TARGETS SALOMELog EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) + ADD_LIBRARY(SALOMEBasics ${SALOMEBasics_SOURCES}) INSTALL(TARGETS SALOMEBasics EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) -TARGET_LINK_LIBRARIES(SALOMEBasics ${PLATFORM_LIBS} ${PTHREAD_LIBRARIES}) +TARGET_LINK_LIBRARIES(SALOMEBasics SALOMELog ${PLATFORM_LIBS} ${PTHREAD_LIBRARIES}) FILE(GLOB SALOMEBasics_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx") INSTALL(FILES ${SALOMEBasics_HEADERS_HXX} DESTINATION ${SALOME_INSTALL_HEADERS}) -SET(KernelBasis_HEADERS KernelBasis.hxx KernelBasis.i) +SET(KernelBasis_HEADERS baseutilities.h KernelBasis.hxx KernelBasis.i) SET(KernelBasis_SOURCES ${KernelBasis_HEADERS}) SET_SOURCE_FILES_PROPERTIES(KernelBasis.i PROPERTIES CPLUSPLUS ON) SET_SOURCE_FILES_PROPERTIES(KernelBasis.i PROPERTIES SWIG_FLAGS "-py3") diff --git a/src/Basics/HeatMarcel.cxx b/src/Basics/HeatMarcel.cxx new file mode 100644 index 000000000..a461a2288 --- /dev/null +++ b/src/Basics/HeatMarcel.cxx @@ -0,0 +1,162 @@ +// Copyright (C) 2023 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "HeatMarcel.hxx" + +#include "baseutilities.h" + +#include +#include +#include +#include +#include +#include + +#include + +template +static void GetSlice(T start, T stop, const unsigned int sliceId, const unsigned int nbOfSlices, T& startSlice, T& stopSlice) +{ + T nbElems=stop - start; + T minNbOfElemsPerSlice=nbElems/nbOfSlices; + startSlice=start+minNbOfElemsPerSlice*sliceId; + if(sliceId threads(nbThreads); + std::vector res(nbThreads); + for(auto iCore = 0 ; iCore < nbThreads ; ++iCore) + { + std::uint64_t startSlice,stopSlice; + GetSlice(0,nbTurn,iCore,nbThreads,startSlice,stopSlice); + long double *resLoc = res.data()+iCore; + threads[iCore] = std::thread([nbTurn,startSlice,stopSlice,resLoc]{ SimulateOneCoreOfComputationNode(startSlice,stopSlice,nbTurn,resLoc);}); + } + SIMPLE_MESSAGE( "Number of processors " << nbThreads ); + for(auto& th : threads) + th.join(); + long double ret = std::accumulate(res.begin(),res.end(),0.0); + return ret; +} + +constexpr long double CST = 161000000; // CST - estabished with gcc8.5.0 in debug mode + +static std::uint64_t GetNbTurnFromTimeControler(double timeControler) +{ + return static_cast( timeControler * CST ); +} + +/*! +* long double& ret let it in output to force computation + */ +static std::int64_t GetNbOfNsFor(double timeControler, long double& ret) +{ + std::uint64_t nbTurn = GetNbTurnFromTimeControler( timeControler ); + auto start = std::chrono::high_resolution_clock::now(); + SimulateOneCoreOfComputationNode(0,nbTurn,nbTurn,&ret); + auto end = std::chrono::high_resolution_clock::now(); + return std::chrono::duration_cast(end - start).count(); +} + +/*! +* long double& ret let it in output to force computation + */ +static double FunctionToSolve(double timeControler, long double& fake) +{ + std::int64_t timeInNs = GetNbOfNsFor(timeControler,fake); + long double ret = (long double )timeInNs / ((long double) 1000000000); + return ret; +} + +/*! +* long double& ret let it in output to force computation + */ +static double Derivative(double timeControler, long double& fake) +{ + long double fake1,fake2; + double a = FunctionToSolve(timeControler,fake1); + double b = FunctionToSolve(2*timeControler,fake2); + fake = fake1 + fake2; + return (b-a)/(timeControler); +} + +/* + * The returned value is those to pass to ActiveSleepOfComputationNode to + * have an active sleep of 1s on one core. + * + * Higher is the returned value most performant is your processor and/or the generated binary + * + * Some exemple on core i7-6700 of 2020 on gcc 6.3 and 8.5 + * In debug mode : ~ 1 + * In O2 mode : ~ 4.3 + */ +double SALOME::GetTimeAdjustmentCst() +{ + long double fake; + double ret = Derivative(0.5,fake); + // Do not remove fake variable because if you do so compiler is too smart and stop computing :) + if(fake > 0.0) + return 1.0/ret; + return 1.0; +} + +/* + * This method can be seen as a active sleep that occupies cores (piloted by \a nbThreads) of hosting computation node. + * Of course the time spend by this method cannot be controled finely due to dependancy of the activity on hosted machine / OS. + * This method only occupies cores without any stress of the memory. + * This method can be used to assess good usage of computation nodes on a massive YACS graph. + * + * /param [in] timeAjustment : pilot time spend for the active sleep. The duration is linearly controled by this input and inversly linearly to the \a nbThreads parameter. + * \param [out] timeInS : return the time in second of the active sleep + * \param [in] nbThreads : Specify the number of thread on which the computation will be launched. If 0 (the default) all cores of hosting machine will be used. + * \return is pi value computed in a naive way :) This return value is necessary to prevent aggressive compiler to not compute. + * + * \sa GetTimeAdjustmentCstOnYourSystem : to help you to fine tune \a timeAjustment parameter + */ +long double SALOME::HeatMarcel(double timeAjustment, double& timeInS, unsigned int nbThreads) +{ + std::uint64_t nbTurn = GetNbTurnFromTimeControler( timeAjustment ); + unsigned int nbThreadsEff = nbThreads == 0?std::thread::hardware_concurrency():nbThreads; + auto start = std::chrono::high_resolution_clock::now(); + long double ret = SimulateOnAllCoresOfComputationNodeInternal(nbTurn, nbThreadsEff); + auto end = std::chrono::high_resolution_clock::now(); + timeInS = ((double)(std::chrono::duration_cast(end - start).count()))/1000000000.0; + return 4.0 * ret; +} diff --git a/src/Basics/HeatMarcel.hxx b/src/Basics/HeatMarcel.hxx new file mode 100644 index 000000000..7ab5bff9f --- /dev/null +++ b/src/Basics/HeatMarcel.hxx @@ -0,0 +1,29 @@ +// Copyright (C) 2023 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#pragma once + +#include "SALOME_Basics.hxx" + +namespace SALOME +{ + double BASICS_EXPORT GetTimeAdjustmentCst(); + + long double BASICS_EXPORT HeatMarcel(double timeAjustment, double& timeInS, unsigned int nbThreads = 0); +} diff --git a/src/Basics/KernelBasis.i b/src/Basics/KernelBasis.i index 84af10fa3..fdc4df0a9 100644 --- a/src/Basics/KernelBasis.i +++ b/src/Basics/KernelBasis.i @@ -21,10 +21,14 @@ %{ #include "KernelBasis.hxx" +#include "HeatMarcel.hxx" +using namespace SALOME; %} %include "std_string.i" +%rename (HeatMarcel) HeatMarcelSwig; + bool getSSLMode(); void setSSLMode(bool sslMode); @@ -33,3 +37,18 @@ void setGUIMode(bool guiMode); std::string getIOROfEmbeddedNS(); void setIOROfEmbeddedNS(const std::string& ior); + +double GetTimeAdjustmentCst(); + +%inline +{ +PyObject *HeatMarcelSwig(double timeAjustment, unsigned int nbThreads = 0) +{ + double timeInS = 0.0; + long double piVal = HeatMarcel(timeAjustment,timeInS,nbThreads); + PyObject *ret(PyTuple_New(2)); + PyTuple_SetItem(ret,0,SWIG_From_double((double)piVal)); + PyTuple_SetItem(ret,1,SWIG_From_double(timeInS)); + return ret; +} +} diff --git a/src/Basics/baseutilities.h b/src/Basics/baseutilities.h new file mode 100644 index 000000000..9db3a5cab --- /dev/null +++ b/src/Basics/baseutilities.h @@ -0,0 +1,29 @@ +// Copyright (C) 2023 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "libSALOMELog.hxx" +#include +#include + +#pragma once + +#define SIMPLE_MESS_END std::endl; std::cout << os.str() << std::flush; +#define SIMPLE_MESS_INIT(deb) std::ostringstream os; os<< deb +#define SIMPLE_MESS_BEGIN(deb) SIMPLE_MESS_INIT(deb)<<__FILE__ <<" ["<<__LINE__<<"] : " +#define SIMPLE_MESSAGE(msg) { if (SALOME::VerbosityActivated()) {SIMPLE_MESS_BEGIN("- Trace ") << msg << SIMPLE_MESS_END}} diff --git a/src/SALOMELocalTrace/libSALOMELog.cxx b/src/Basics/libSALOMELog.cxx similarity index 94% rename from src/SALOMELocalTrace/libSALOMELog.cxx rename to src/Basics/libSALOMELog.cxx index 1d22d33ca..cfaaeada5 100644 --- a/src/SALOMELocalTrace/libSALOMELog.cxx +++ b/src/Basics/libSALOMELog.cxx @@ -1,8 +1,5 @@ // Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either diff --git a/src/SALOMELocalTrace/libSALOMELog.hxx b/src/Basics/libSALOMELog.hxx similarity index 78% rename from src/SALOMELocalTrace/libSALOMELog.hxx rename to src/Basics/libSALOMELog.hxx index 47f364a4f..1a53ec133 100644 --- a/src/SALOMELocalTrace/libSALOMELog.hxx +++ b/src/Basics/libSALOMELog.hxx @@ -1,8 +1,5 @@ // Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either @@ -25,14 +22,11 @@ // Module : KERNEL // $Header$ // -#ifndef _LIBSALOMELOG_HXX_ -#define _LIBSALOMELOG_HXX_ +#pragma once -#include "SALOME_LocalTrace.hxx" +#include "SALOME_Basics.hxx" namespace SALOME { - bool SALOMELOCALTRACE_EXPORT VerbosityActivated(); + bool BASICS_EXPORT VerbosityActivated(); } - -#endif diff --git a/src/SALOMELocalTrace/CMakeLists.txt b/src/SALOMELocalTrace/CMakeLists.txt index 747bba435..e512a0e10 100644 --- a/src/SALOMELocalTrace/CMakeLists.txt +++ b/src/SALOMELocalTrace/CMakeLists.txt @@ -28,7 +28,6 @@ SET(COMMON_HEADERS LocalTraceBufferPool.hxx BaseTraceCollector.hxx SALOME_LocalTrace.hxx - libSALOMELog.hxx ) SET(SALOMELocalTrace_SOURCES @@ -41,12 +40,10 @@ SET(SALOMELocalTrace_SOURCES LocalTraceBufferPool.cxx LocalTraceBufferPool.hxx SALOME_LocalTrace.hxx - libSALOMELog.hxx - libSALOMELog.cxx ) ADD_LIBRARY(SALOMELocalTrace ${SALOMELocalTrace_SOURCES}) -TARGET_LINK_LIBRARIES(SALOMELocalTrace SALOMEBasics ${PLATFORM_LIBS} ${PTHREAD_LIBRARIES}) +TARGET_LINK_LIBRARIES(SALOMELocalTrace SALOMEBasics SALOMELog ${PLATFORM_LIBS} ${PTHREAD_LIBRARIES}) INSTALL(TARGETS SALOMELocalTrace EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) INSTALL(FILES ${COMMON_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS}) -- 2.39.2