Import Geant4 11.1.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2022-07-01 10:44:02 +02:00
parent b3bf75a2a1
commit c07cea1fe0
2172 changed files with 183300 additions and 123938 deletions
+106 -9
View File
@@ -25,15 +25,24 @@
#include "PTL/Threading.hh"
#include "PTL/AutoLock.hh"
#include "PTL/Globals.hh"
#include "PTL/Types.hh"
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
#if defined(PTL_WINDOWS)
# include <Windows.h>
#else
#elif defined(PTL_UNIX)
# include <sys/syscall.h>
# include <sys/types.h>
# include <unistd.h>
#endif
#if defined(PTL_MACOS)
# include <sys/sysctl.h>
#endif
#if defined(PTL_LINUX)
# include <fstream>
#endif
#include <atomic>
using namespace PTL;
@@ -43,6 +52,7 @@ using namespace PTL;
namespace
{
thread_local int ThreadID = Threading::MASTER_ID;
} // namespace
//======================================================================================//
@@ -64,6 +74,50 @@ Threading::GetNumberOfCores()
//======================================================================================//
unsigned
Threading::GetNumberOfPhysicalCpus()
{
#if defined(PTL_MACOS)
int count;
size_t count_len = sizeof(count);
sysctlbyname("hw.physicalcpu", &count, &count_len, nullptr, 0);
return static_cast<unsigned>(count);
#elif defined(PTL_LINUX)
unsigned core_id_count = 0;
std::ifstream ifs("/proc/cpuinfo");
if(ifs)
{
std::set<std::string> core_ids;
while(true)
{
std::string line = {};
getline(ifs, line);
if(!ifs.good())
break;
if(line.find("core id") != std::string::npos)
{
for(std::string itr : { "core id", ":", " ", "\t" })
{
static auto _npos = std::string::npos;
auto _pos = _npos;
while((_pos = line.find(itr)) != _npos)
line = line.replace(_pos, itr.length(), "");
}
core_ids.insert(line);
}
}
core_id_count = static_cast<unsigned>(core_ids.size());
if(core_id_count > 0)
return core_id_count;
}
return GetNumberOfCores();
#else
return GetNumberOfCores();
#endif
}
//======================================================================================//
void
Threading::SetThreadId(int value)
{
@@ -79,16 +133,59 @@ Threading::GetThreadId()
//======================================================================================//
bool
Threading::SetPinAffinity(int cpu, NativeThread& aT)
Threading::SetPinAffinity(int _cpu)
{
#if defined(__linux__) || defined(_AIX)
cpu_set_t* aset = new cpu_set_t;
CPU_ZERO(aset);
CPU_SET(cpu, aset);
pthread_t& _aT = static_cast<pthread_t&>(aT);
return (pthread_setaffinity_np(_aT, sizeof(cpu_set_t), aset) == 0);
cpu_set_t _cpu_set{};
CPU_ZERO(&_cpu_set);
if(_cpu >= 0)
CPU_SET(_cpu, &_cpu_set);
return (pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &_cpu_set) == 0);
#else // Not available for Mac, WIN,...
ConsumeParameters(cpu, aT);
ConsumeParameters(_cpu);
return true;
#endif
}
//======================================================================================//
bool
Threading::SetThreadPriority(int _prio)
{
#if defined(__linux__) || defined(_AIX)
return (pthread_setschedprio(pthread_self(), _prio) == 0);
#else // Not available for Mac, WIN,...
ConsumeParameters(_prio);
return true;
#endif
}
//======================================================================================//
bool
Threading::SetPinAffinity(int _cpu, NativeThread& _t)
{
#if defined(__linux__) || defined(_AIX)
cpu_set_t _cpu_set{};
CPU_ZERO(&_cpu_set);
CPU_SET(_cpu, &_cpu_set);
return (pthread_setaffinity_np(static_cast<pthread_t>(_t), sizeof(cpu_set_t),
&_cpu_set) == 0);
#else // Not available for Mac, WIN,...
ConsumeParameters(_cpu, _t);
return true;
#endif
}
//======================================================================================//
bool
Threading::SetThreadPriority(int _prio, NativeThread& _t)
{
#if defined(__linux__) || defined(_AIX)
return (pthread_setschedprio(static_cast<pthread_t>(_t), _prio) == 0);
#else
ConsumeParameters(_prio, _t);
return true;
#endif
}