16 #ifndef LIFOSTORAGECOMMON_HPP
17 #define LIFOSTORAGECOMMON_HPP
22 #include <condition_variable>
23 #include <camp/camp.hpp>
29 #ifdef LIFO_DISABLE_CALIPER
30 #define LIFO_MARK_FUNCTION
31 #define LIFO_MARK_SCOPE( a )
32 #define LIFO_LOG_RANK( a ) std::cerr << a << std::endl;
34 #define LIFO_MARK_FUNCTION GEOS_MARK_FUNCTION
35 #define LIFO_MARK_SCOPE( a ) GEOS_MARK_SCOPE( a )
36 #define LIFO_LOG_RANK( a ) GEOS_LOG_RANK( a )
39 #include "common/GEOS_RAJA_Interface.hpp"
41 #include "common/FixedSizeDequeWithMutexes.hpp"
42 #include "common/MultiMutexesLock.hpp"
50 template<
typename T,
typename INDEX_TYPE >
69 m_hostDeque( numberOfBuffersToStoreOnHost, elemCnt, LvArray::MemorySpace::host ),
122 LIFO_LOG_RANK(
" LIFO : warning number of entered buffered (" <<
m_bufferCount
125 for(
int queueId = 0; queueId < 2; queueId++ )
159 GEOS_ERROR_IF( percent > 100,
"Error, percentage of memory should be smallerer than -100, check lifoOnHost (should be greater that -100)" );
160 #if defined( _SC_AVPHYS_PAGES ) && defined( _SC_PAGESIZE )
161 size_t const free = sysconf( _SC_AVPHYS_PAGES ) * sysconf( _SC_PAGESIZE );
163 size_t const free = 0;
164 GEOS_ERROR(
"To use LifoStorage, both _SC_AVPHYS_PAGES and _SC_PAGESIZE must be defined." );
166 int numberOfBuffersToStoreOnHost = std::max( 1, std::min( (
int )( 0.01 * percent * free / bufferSize ), maxNumberOfBuffers - numberOfBuffersToStoreOnDevice ) );
168 LIFO_LOG_RANK(
" LIFO : available memory on host " << freeGB <<
" GB" );
169 return numberOfBuffersToStoreOnHost;
245 return stat( dirName.c_str(), &buffer ) == 0;
258 int lastDirSeparator = fileName.find_last_of(
"/\\" );
259 std::string dirName = fileName.substr( 0, lastDirSeparator );
260 if( string::npos != (
size_t)lastDirSeparator && !
dirExists( dirName ))
263 std::ofstream wf( fileName, std::ios::out | std::ios::binary );
265 "Could not open file "<< fileName <<
" for writting" );
268 "An error occured while writting "<< fileName );
282 std::ifstream wf( fileName, std::ios::in | std::ios::binary );
284 "Could not open file "<< fileName <<
" for reading" );
287 remove( fileName.c_str() );
297 void wait_and_consume_tasks(
int queueId )
304 LIFO_MARK_SCOPE( waitForTask );
308 std::packaged_task< void() > task( std::move(
m_task_queue[queueId].front() ) );
313 LIFO_MARK_SCOPE( runningTask );
#define GEOS_ERROR(msg)
Raise a hard error and terminate the program.
#define GEOS_ERROR_IF(EXP, msg)
Conditionally raise a hard error and terminate the program.
Associate mutexes with the fixedSizeDeque.
virtual void pushAsync(arrayView1d< T > array)=0
int m_bufferCount
counter of buffer stored in LIFO
int m_bufferToDiskCount
counter of buffer pushed to disk
static int computeNumberOfBufferOnHost(int percent, size_t bufferSize, int maxNumberOfBuffers, int numberOfBuffersToStoreOnDevice)
std::string m_name
name used to store data on disk
FixedSizeDequeWithMutexes< T, INDEX_TYPE > m_hostDeque
Queue of data stored on host memory.
void readOnDisk(T *d, int id)
virtual void popAsync(arrayView1d< T > array)=0
std::deque< std::packaged_task< void() > > m_task_queue[2]
queue of task to be executed by m_worker.
std::mutex m_task_queue_mutex[2]
mutex to protect access to m_task_queue.
std::thread m_worker[2]
thread to execute tasks.
std::condition_variable m_task_queue_not_empty_cond[2]
condition used to tell m_worker queue has been filled or processed is stopped.
size_t m_bufferSize
size of one buffer in bytes
virtual void pushWait()=0
LifoStorageCommon(std::string name, size_t elemCnt, int numberOfBuffersToStoreOnHost, int maxNumberOfBuffers)
bool dirExists(const std::string &dirName)
int m_bufferToHostCount
counter of buffer pushed to host
bool m_hasPoppedBefore
marker to detect first pop
bool m_continue
boolean to keep m_worker alive.
int m_maxNumberOfBuffers
number of buffers to be inserted into the LIFO
void writeOnDisk(const T *d, int id)
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
auto make_multilock(Mutexes &&... mutexes)
Helper to construct MultiMutexesLock (usage auto lock = make_multilock( mutex1, mutex2,...
std::string string
String type.
void makeDirsForPath(std::string const &path)
Make directories for path.
static int nodeCommSize()
Compute the number of ranks allocated on the same node.