37#ifndef __PARA_COMM_PTH_H__
38#define __PARA_COMM_PTH_H__
57#define HashEntry( tid ) ( hashCode(tid) % UG::HashTableSize )
59#define TAG_TRACE( call, fromTo, sourceDest, tag ) \
65 *getOstream() << timer.getRTimeInterval() << " [Rank = " << getRank() << "] " << #call << " " << #fromTo \
66 << " " << sourceDest << " with Tag = " << getTagString(tag) << std::endl; \
71 *getOstream() << timer.getRTimeInterval() << " [Rank = " << getRank() << "] " << #call << " " << #fromTo \
72 << " " << sourceDest << " as broadcast" << std::endl; \
231class MessageQueueTableElement
236 MessageQueueElement *
head;
237 MessageQueueElement *
tail;
282 if( current->getSource() == source
283 && current->getDataTypeId() == datatypeId
284 && current->getTag() == tag )
306 if( current->getTag() == tag )
337 && current->
getTag() == tag )
341 if( current ==
head )
343 if( current ==
tail )
347 *sentMessage =
false;
356 if( current ==
tail )
385 if(
head == 0 )
return 0;
390 if( current ==
tail )
394 *sentMessage =
false;
458 if(
head ) empty =
false;
460 assert( !empty ||
size == 0 );
496 && current->
getTag() == tag )
503 *sentMessage =
false;
541 && current->
getTag() == (*tag) )
549 *sentMessage =
false;
558class ThreadsTableElement
561#ifdef _UG_NO_THREAD_LOCAL_STATIC
575#ifdef _UG_NO_THREAD_LOCAL_STATIC
586#ifdef _UG_NO_THREAD_LOCAL_STATIC
592#ifdef _UG_NO_THREAD_LOCAL_STATIC
605 std::ostringstream s;
607 std::ofstream *ofs =
new std::ofstream();
608 ofs->open(s.str().c_str());
622 if(
tos != &std::cout )
624 std::ofstream *ofs =
dynamic_cast<std::ofstream *
>(
tos);
631#ifdef _UG_NO_THREAD_LOCAL_STATIC
683#ifdef _UG_NO_THREAD_LOCAL_STATIC
694class ParaCalculationState;
696class ParaSolverState;
697class ParaSolverTerminationState;
698class ParaDiffSubproblem;
718#ifndef _UG_NO_THREAD_LOCAL_STATIC
859 for(
int i = 0; i < (
comSize + 1 ); i++ )
863 return nTotalMessages;
1067 const int datatypeId,
1078 const int datatypeId,
1090 const int datatypeId,
1128 const int datatypeId,
1139 const int datatypeId,
1154#define DEF_PARA_COMM( para_comm, comm ) ParaCommPth *para_comm = dynamic_cast< ParaCommPth* >(comm)
1155#define LOCK_APP( comm ) comm->lockApp(__FILE__, __LINE__)
1156#define LOCK_RANK( comm ) comm->lockRank(__FILE__, __LINE__)
1157#define UNLOCK_RANK( comm ) comm->unlockRank(__FILE__, __LINE__)
Class that implements a lock. The class wraps around pthread_mutex_t and adds some safeguards.
void unlock()
Release this lock.
void lock()
Acquire this lock. The function sets the internal file/line (debugging) fields to generic values.
Class for message queue element.
int source
source thread rank of this message
int dataTypeId
data type id
int getSource()
getter of source rank
MessageQueueElement()
default constructor of MessageQueueElement
MessageQueueElement * next
point to next message queue element
int getDataTypeId()
getter of the data type id
void link(MessageQueueElement *nextElement)
link to the next MessageQueueElement
MessageQueueElement(int inSource, int inCount, int inDataTypeId, int inTag, void *inData)
constructor of MessageQueueElement
int tag
tag of the message, -1 : in case of broadcast message
void * getData()
getter of data
void * data
data of the message
int count
number of the data type elements
int getTag()
getter of the message tag
~MessageQueueElement()
destructor of MessageQueueElement
int getCount()
getter of the number of the data type elements
MessageQueueElement * getNext()
getter of the pointer to the next MessageQueueElement
Class of MessageQueueTableElement.
MessageQueueElement * extarctElement(bool *sentMessage, int source, int datatypeId, int tag)
extracts a message
int getSize()
getter of size
int size
number of the messages in queue
void waitMessage(ConditionVariable *sentMsg, bool *sentMessage, int source, int datatypeId, int tag)
wait for a specified message coming to a queue
MessageQueueElement * extarctElement(bool *sentMessage)
extracts a message (This method is only for desctructor of ParaCommCPP11. No lock is necessary....
MessageQueueElement * getHead()
getter of head
MessageQueueElement * tail
tail of the message queue
void enqueue(ConditionVariable *sentMsg, bool *sentMessage, MessageQueueElement *newElement)
enqueue a message
MessageQueueElement * checkElement(int source, int datatypeId, int tag)
check if the specified message exists or nor
~MessageQueueTableElement()
destructor of MessageQueueTableElement
MessageQueueTableElement()
default constructor of MessageQueueTableElement
void waitMessage(ConditionVariable *sentMsg, bool *sentMessage)
wait for a message coming to a queue
MessageQueueElement * head
head of the message queue
MessageQueueElement * checkElementWithTag(int tag)
check if the specified message with tag exists or nor
void waitMessage(ConditionVariable *sentMsg, bool *sentMessage, int source, int *tag)
wait for a specified message coming to a queue
bool isEmpty()
check if the queue is empty or not
Communicator object for pthreads thread communications.
int comSize
communicator size : number of threads joined in this system
bool probe(int *source, int *tag)
probe function which waits a new message
int send(void *bufer, int count, const int datatypeId, int dest, const int tag)
send function for standard ParaData types
void unlockRank()
unlock rank
int ** token
index 0: token index 1: token color -1: green > 0: yellow ( termination origin solver number ) -2: re...
bool iProbe(int *source, int *tag)
iProbe function which checks if a new message is arrived or not
Lock * queueLock
Lock for synchronization.
void solverInit(ParaParamSet *paraParamSet)
initializer for Solvers
int receive(void *bufer, int count, const int datatypeId, int source, const int tag)
receive function for standard ParaData types
void freeMem(void *buffer, int count, const int datatypeId)
free memory
std::ostream * getOstream()
get ostream pointer
int getSize()
get size of this communicator, which indicates how many threads in a UG process
virtual bool tagStringTableIsSetUpCoorectly()
check if tag string table (for debugging) set up correctly
bool tagTraceFlag
indicate if tags are traced or not
void * allocateMemAndCopy(const void *buffer, int count, const int datatypeId)
allocate memory and copy message
int uTypeSend(void *bufer, const int datatypeId, int dest, int tag)
User type send for created data type.
bool waitTerminatedMessage()
function to wait Terminated message (This function is not used currently)
void lockApp()
lock UG application to synchronize with other threads
virtual const char * getTagString(int tag)
get Tag string for debugging
ParaSysTimer timer
system timer
int uTypeReceive(void **bufer, const int datatypeId, int source, int tag)
User type receive for created data type.
void passToken(int rank)
pass token to from the rank to the next
Lock * tokenAccessLock
lock to access token
void registedAllSolvers()
notify that all solvers are registered
MessageQueueTableElement ** messageQueueTable
message queue table
unsigned int hashCode(pthread_t tid)
get hash code from thread id
static const char * tagStringTable[]
tag name string table
void waitUntilRegistered()
wait until thread id is registered to thread table
virtual ~ParaCommPth()
destructor of this communicator
void lockApp(char const *f, int l)
lock UG application to synchronize with other threads (for debugging)
static ThreadsTableElement * threadsTable[HashTableSize]
threads table: index is thread rank
double getStartTime()
get start time of this communicator (should not be used)
int getRank()
get rank of caller's thread
virtual void init(int argc, char **argv)
initializer of this communicator
void unlockApp()
unlock UG application to synchronize with other threads
Lock rankLock
lock to access rank
int getNumOfMessagesWaitingToSend(int dest=-1)
get size of the messageQueueTable
ParaTimer * createParaTimer()
create ParaTimer object
void solverDel(int rank)
delete Solver from this communicator
static __thread int localRank
local thread rank
bool freeStandardTypes(MessageQueueElement *elem)
free memory
void abort()
abort. How it works sometimes depends on communicator used
bool * sentMessage
sent message flag for synchronization
void copy(void *dest, const void *src, int count, int datatypeId)
copy message
ConditionVariable * sentMsg
Condition variable for synchronization.
void solverReInit(int rank, ParaParamSet *paraParamSet)
reinitializer of a specific Solver
bool passTermToken(int rank)
pass termination token from the rank to the next
void lockRank(char const *f, int l)
lock rank (for debugging)
void setToken(int rank, int *inToken)
set received token to this communicator
ParaCommPth()
constructor of ParaCommPth
void unlockRank(char const *f, int l)
unlock rank (for debugging)
int bcast(void *buffer, int count, const int datatypeId, int root)
broadcast function for standard ParaData types
void waitSpecTagFromSpecSource(const int source, const int tag, int *receivedTag)
wait function for a specific tag from a specific source coming from
void lcInit(ParaParamSet *paraParamSet)
initializer for LoadCoordinator
Lock applicationLock
lock for application
bool waitToken(int rank)
wait token when UG runs with deterministic mode
Base class of communicator object.
double getStartTime(void)
get start time
class ParaTimerMpi (Timer used in thread communication)
Class of ThreadsTableElement.
void setRank(int r)
setter of this thread rank
ThreadsTableElement * next
next ThradsTableElement pointer
std::ostream * getOstream()
getter of tag trace stream of this rank
~ThreadsTableElement()
destructor of ThreadsTableElement
std::ostream * tos
tag trace stream for this thread
int rank
rank of this thread
int getRank()
getter of this thread rank
ThreadsTableElement(int inRank, ParaParamSet *paraParamSet)
constructor of ThreadsTableElement
ThreadsTableElement * getNext()
get next element
ThreadsTableElement()
default constructor of ThreadsTableElement
static ScipParaParamSet * paraParamSet
static const int TYPE_LAST
static const int UG_USER_TYPE_LAST
static const int ParaTaskType
static const int ParaInstanceType
static const int ParaParamSetType
static const int HashTableSize
size of thread table : this limits the number of threads
static const int ParaSolverStateType
static const int ParaCalculationStateType
static const int ParaSolverTerminationStateType
static const int TagTraceFileName
static const int UG_USER_TYPE_FIRST
user defined transfer data types
static const int ParaSolutionType
static const int ParaRacingRampUpParamType
static const int TagTrace
Base class of communicator for UG Framework.
Defines for UG Framework.
Pthread condition variable for UG Framework.
#define CONDITIONVARIABLE_WAIT(var, cond)
Perform exception-safe waiting on a condition variable. This macro waits on VAR until COND is true.
Pthread lock for UG Framework.
ParaTimer extension for threads.