58#ifndef _UG_NO_THREAD_LOCAL_STATIC
59__thread
int ParaCommPth::localRank = -1;
63ParaCommPth::tagStringTable[] = {
76 TAG_STR(TagRacingRampUpParamSets),
85ParaCommPth::init(
int argc,
char **argv )
92 for(
int i = 1; i < argc; i++ )
94 if( strcmp(argv[i],
"-sth") == 0 )
101 std::cerr <<
"missing the number of solver threads after parameter '-sth'" << std::endl;
113 comSize = sysconf(_SC_NPROCESSORS_CONF) + 1;
118 for(
int i = 0; i <
comSize; i++ )
120 token[i] =
new int[2];
139 for(
int i = 0; i < (
comSize + 1 ); i++ )
158#ifndef _UG_NO_THREAD_LOCAL_STATIC
164 pthread_t tid = pthread_self();
180#ifndef _UG_NO_THREAD_LOCAL_STATIC
187 pthread_t tid = pthread_self();
198 if( pthread_equal( elem->getTid(), tid ) )
220#ifndef _UG_NO_THREAD_LOCAL_STATIC
230 THROW_LOGICAL_ERROR1(
"solverReInit only can work with thread local variable. The following routine should not be used!");
231 pthread_t tid = pthread_self();
242 if( pthread_equal( elem->getTid(), tid ) )
266#ifndef _UG_NO_THREAD_LOCAL_STATIC
280 pthread_t tid = pthread_self();
290 while( elem && !pthread_equal( elem->getTid(), tid ) )
295 if( !elem || !pthread_equal( elem->getTid(), tid ) )
318#ifdef _UG_NO_THREAD_LOCAL_STATIC
319 pthread_t tid = pthread_self();
322 bool registered =
false;
326#ifndef _UG_NO_THREAD_LOCAL_STATIC
334 while( elem && !pthread_equal( elem->getTid(), tid ) )
340 assert( pthread_equal( elem->getTid(), tid ) );
346 solverRanksGenerated.wait();
355 solverRanksGenerated.broadcast();
365 if(
token[rank][0] == rank )
373 probe(&source, &receivedTag);
374 TAG_TRACE (Probe, From, source, receivedTag);
375 if( source == 0 && receivedTag ==
TagToken )
378 assert(
token[rank][0] == rank );
395 assert(
token[rank][0] == rank && rank != 0 );
408 if( rank ==
token[rank][0] )
419 if(
token[rank][1] == -2 )
437 assert( rank == 0 || ( rank != 0 && inToken[0] == rank ) );
438 token[rank][0] = inToken[0];
439 token[rank][1] = inToken[1];
458 for(
int i = 0; i <
comSize; i++ )
465 for(
int i = 0; i < (
comSize + 1); i++)
497 unsigned char cTid[
sizeof(pthread_t)];
500 reinterpret.tid = tid;
502 for (
unsigned int i = 0; i <
sizeof(pthread_t); i++) {
503 h = 31*h + reinterpret.cTid[i];
513#ifndef _UG_NO_THREAD_LOCAL_STATIC
517 pthread_t tid = pthread_self();
520 while( elem && !pthread_equal( elem->getTid(), tid ) )
540#ifdef _UG_NO_THREAD_LOCAL_STATIC
541 pthread_t tid = pthread_self();
544 while( !pthread_equal( elem->getTid(), tid ) )
563 if( count == 0 )
return newBuf;
569 newBuf =
new char[count];
570 memcpy(newBuf, buffer, (
unsigned long int)
sizeof(
char)*count);
575 newBuf =
new short[count];
576 memcpy(newBuf, buffer, (
unsigned long int)
sizeof(
short)*count);
581 newBuf =
new int[count];
582 memcpy(newBuf, buffer, (
unsigned long int)
sizeof(
int)*count);
587 newBuf =
new long[count];
588 memcpy(newBuf, buffer, (
unsigned long int)
sizeof(
long)*count);
593 newBuf =
new unsigned char[count];
594 memcpy(newBuf, buffer, (
unsigned long int)
sizeof(
unsigned char)*count);
599 newBuf =
new unsigned short[count];
600 memcpy(newBuf, buffer, (
unsigned long int)
sizeof(
unsigned short)*count);
605 newBuf =
new unsigned int[count];
606 memcpy(newBuf, buffer, (
unsigned long int)
sizeof(
unsigned int)*count);
611 newBuf =
new unsigned long[count];
612 memcpy(newBuf, buffer, (
unsigned long int)
sizeof(
unsigned long)*count);
617 newBuf =
new float[count];
618 memcpy(newBuf, buffer, (
unsigned long int)
sizeof(
float)*count);
623 newBuf =
new double[count];
624 memcpy(newBuf, buffer, (
unsigned long int)
sizeof(
double)*count);
629 newBuf =
new long double[count];
630 memcpy(newBuf, buffer, (
unsigned long int)
sizeof(
long double)*count);
635 newBuf =
new char[count];
636 memcpy(newBuf, buffer, (
unsigned long int)
sizeof(
char)*count);
641 newBuf =
new char[count];
642 memcpy(newBuf, buffer, (
unsigned long int)
sizeof(
char)*count);
647 newBuf =
new long long[count];
648 memcpy(newBuf, buffer, (
unsigned long int)
sizeof(
long long)*count);
653 newBuf =
new unsigned long long[count];
654 memcpy(newBuf, buffer, (
unsigned long int)
sizeof(
unsigned long long)*count);
659 newBuf =
new bool[count];
660 memcpy(newBuf, buffer, (
unsigned long int)
sizeof(
bool)*count);
672 void *dest,
const void *src,
int count,
int datatypeId
676 if( count == 0 )
return;
682 memcpy(dest, src, (
unsigned long int)
sizeof(
char)*count);
687 memcpy(dest, src, (
unsigned long int)
sizeof(
short)*count);
692 memcpy(dest, src, (
unsigned long int)
sizeof(
int)*count);
697 memcpy(dest, src, (
unsigned long int)
sizeof(
long)*count);
702 memcpy(dest, src, (
unsigned long int)
sizeof(
unsigned char)*count);
707 memcpy(dest, src, (
unsigned long int)
sizeof(
unsigned short)*count);
712 memcpy(dest, src, (
unsigned long int)
sizeof(
unsigned int)*count);
717 memcpy(dest, src, (
unsigned long int)
sizeof(
unsigned long)*count);
722 memcpy(dest, src, (
unsigned long int)
sizeof(
float)*count);
727 memcpy(dest, src, (
unsigned long int)
sizeof(
double)*count);
732 memcpy(dest, src, (
unsigned long int)
sizeof(
long double)*count);
737 memcpy(dest, src, (
unsigned long int)
sizeof(
char)*count);
742 memcpy(dest, src, (
unsigned long int)
sizeof(
char)*count);
747 memcpy(dest, src, (
unsigned long int)
sizeof(
long long)*count);
752 memcpy(dest, src, (
unsigned long int)
sizeof(
unsigned long long)*count);
757 memcpy(dest, src, (
unsigned long int)
sizeof(
bool)*count);
774 if( count == 0 )
return;
780 delete []
static_cast<char *
>(buffer);
785 delete []
static_cast<short *
>(buffer);
790 delete []
static_cast<int *
>(buffer);
795 delete []
static_cast<long *
>(buffer);
800 delete []
static_cast<unsigned char *
>(buffer);
805 delete []
static_cast<unsigned short *
>(buffer);
810 delete []
static_cast<unsigned int *
>(buffer);
815 delete []
static_cast<unsigned long *
>(buffer);
820 delete []
static_cast<float *
>(buffer);
825 delete []
static_cast<double *
>(buffer);
830 delete []
static_cast<long double *
>(buffer);
835 delete []
static_cast<char *
>(buffer);
840 delete []
static_cast<char *
>(buffer);
845 delete []
static_cast<long long *
>(buffer);
850 delete []
static_cast<unsigned long long *
>(buffer);
855 delete []
static_cast<bool *
>(buffer);;
947 const int datatypeId,
957 send(buffer, count, datatypeId, i, -1);
963 receive(buffer, count, datatypeId, root, -1);
972 const int datatypeId,
991 const int datatypeId,
1007 copy( buffer, elem->
getData(), count, datatypeId );
1030 (*receivedTag) = tag;
1033 TAG_TRACE (Probe, From, source, *receivedTag);
1070 TAG_TRACE (Iprobe, From, *source, *tag);
1080 TAG_TRACE (Iprobe, From, *source, *tag);
1091 const int datatypeId,
1108 const int datatypeId,
void setLock(Lock *l)
set Lock from outside.
Class that implements a lock. The class wraps around pthread_mutex_t and adds some safeguards.
Class for message queue element.
int getSource()
getter of source rank
int getDataTypeId()
getter of the data type id
void * getData()
getter of data
int getTag()
getter of the message tag
int getCount()
getter of the number of the data type elements
Class of MessageQueueTableElement.
void enqueue(std::condition_variable &sentMsg, std::mutex &queueLockMutex, bool *sentMessage, MessageQueueElement *newElement)
enqueue a message
MessageQueueElement * extarctElement(bool *sentMessage, int source, int datatypeId, int tag)
extracts a message
MessageQueueElement * getHead()
getter of head
void waitMessage(std::condition_variable &sentMsg, std::mutex &queueLockMutex, bool *sentMessage)
wait for a message coming to a queue
MessageQueueElement * checkElementWithTag(int tag)
check if the specified message with tag exists or nor
bool isEmpty()
check if the queue is empty or not
Base class of Calculation state in a ParaSolver.
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
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
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.
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
static ThreadsTableElement * threadsTable[HashTableSize]
threads table: index is thread rank
int getRank()
get rank of caller's thread
void solverDel(int rank)
delete Solver from this communicator
static __thread int localRank
local thread rank
bool freeStandardTypes(MessageQueueElement *elem)
free memory
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 setToken(int rank, int *inToken)
set received token to this communicator
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
bool waitToken(int rank)
wait token when UG runs with deterministic mode
class ParaRacingRampUpParamSet (parameter set for racing ramp-up)
class ParaSolverState (ParaSolver state object for notification message)
class ParaSolverTerminationState (Solver termination state in a ParaSolver)
void start(void)
start timer
Class of ThreadsTableElement.
void setRank(int r)
setter of this thread rank
std::ostream * getOstream()
getter of tag trace stream of this rank
int getRank()
getter of this thread rank
ThreadsTableElement * getNext()
get next element
static ScipParaParamSet * paraParamSet
static const int ParaUNSIGNED_LONG
static const int TagAckCompletion
static const int TagCompletionOfCalculation
static const int TagWinner
static const int ParaTaskType
static const int ParaInstanceType
static const int TagSolution
static const int ParaUNSIGNED_SHORT
static const int TagToken
static const int TagTaskReceived
static const int N_TH_TAGS
static const int TagInterruptRequest
static const int TagNotificationId
static const int ParaParamSetType
static const int TagIncumbentValue
static const int HashTableSize
size of thread table : this limits the number of threads
static const int ParaLONG_DOUBLE
static const int TagTerminated
static const int ParaSolverStateType
static const int ParaCalculationStateType
static const int ParaLONG
static const int TagTerminateRequest
static const int ParaBYTE
static const int ParaSolverTerminationStateType
static const int ParaUNSIGNED
static const int TagRampUp
static const int TagSolverState
static const int TagHardTimeLimit
static const int ParaFLOAT
static const int ParaBOOL
static const int ParaCHAR
static const int UG_USER_TYPE_FIRST
user defined transfer data types
static const int TagDiffSubproblem
static const int ParaSolutionType
static const int ParaRacingRampUpParamType
static const int TagParaInstance
static const int ParaSHORT
static const int TagTrace
static const int ParaUNSIGNED_LONG_LONG
static const int ParaLONG_LONG
static const int ParaUNSIGNED_CHAR
static const int ParaDOUBLE
static const int ParaSIGNED_CHAR
Base class for calculation state.
#define TAG_TRACE(call, fromTo, sourceDest, tag)
ParaComm extension for Pthreads communication.
#define THROW_LOGICAL_ERROR1(msg1)
#define ABORT_LOGICAL_ERROR2(msg1, msg2)
#define THROW_LOGICAL_ERROR2(msg1, msg2)
#define THROW_LOGICAL_ERROR4(msg1, msg2, msg3, msg4)
Base class for initial statistics collecting class.
Base class for racing ramp-up parameter set.
This class has solver state to be transferred.
This class contains solver termination state which is transferred form Solver to LC.