Skip to content

Commit

Permalink
Refs #10330. ThreadPool should no longer depend on openmp
Browse files Browse the repository at this point in the history
  • Loading branch information
quantumsteve committed Oct 14, 2014
1 parent e189c59 commit 66365f3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
Expand Up @@ -19,6 +19,7 @@

#include <istream>
#include <Poco/Thread.h>
#include <Poco/Mutex.h>

namespace Mantid
{
Expand Down Expand Up @@ -73,6 +74,8 @@ class MANTID_KERNEL_DLL ThreadSafeLogStreamBuf: public Poco::LogStreamBuf
private:
/// Store a map of thread indices to messages
std::map<Poco::Thread::TID, std::string> m_messages;
/// mutex protecting logstream
Poco::Mutex m_mutex;
};


Expand Down
12 changes: 5 additions & 7 deletions Code/Mantid/Framework/Kernel/src/ThreadPool.cpp
@@ -1,7 +1,6 @@
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidKernel/MultiThreaded.h"
#include "MantidKernel/ThreadPool.h"
#include "MantidKernel/ThreadPoolRunnable.h"
#include "MantidKernel/Task.h"
Expand All @@ -12,6 +11,7 @@
#include <Poco/Mutex.h>
#include <Poco/Runnable.h>
#include <Poco/Thread.h>
#include <Poco/Environment.h>

namespace Mantid
{
Expand Down Expand Up @@ -39,7 +39,7 @@ namespace Kernel
if (numThreads == 0)
{
//Uses OpenMP to find how many cores there are.
m_numThreads = PARALLEL_GET_MAX_THREADS;
m_numThreads = getNumPhysicalCores();
}
else
m_numThreads = numThreads;
Expand All @@ -60,16 +60,14 @@ namespace Kernel

//--------------------------------------------------------------------------------
/** Return the number of physical cores available on the system.
* NOTE: Uses OpenMP getMaxThreads to find the number.
* @return how many cores are present. 1 if no OpenMP is installed.
* NOTE: Uses Poco::Environment::processorCount() to find the number.
* @return how many cores are present.
*/
size_t ThreadPool::getNumPhysicalCores()
{
return PARALLEL_GET_MAX_THREADS;
return Poco::Environment::processorCount();
}



//--------------------------------------------------------------------------------
/** Start the threads and begin looking for tasks.
*
Expand Down
6 changes: 2 additions & 4 deletions Code/Mantid/Framework/Kernel/src/ThreadSafeLogStream.cpp
Expand Up @@ -48,10 +48,8 @@ int ThreadSafeLogStreamBuf::writeToDevice(char c)
}
else
{
PARALLEL_CRITICAL(logstream)
{
m_messages[Poco::Thread::currentTid()] += c;
}
Poco::Mutex::ScopedLock lock(m_mutex);
m_messages[Poco::Thread::currentTid()] += c;
}
return static_cast<int>(c);
}
Expand Down

0 comments on commit 66365f3

Please sign in to comment.