58 #ifndef _UG_NO_THREAD_LOCAL_STATIC 76 TAG_STR(TagRacingRampUpParamSets),
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);;
939 assert( tag >= 0 && tag < N_TH_TAGS );
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,
Base class for calculation state.
static const int ParaSHORT
std::ostream * getOstream()
getter of tag trace stream of this rank
class ParaSolverState (ParaSolver state object for notification message)
int getDataTypeId()
getter of the data type id
static const int TagNotificationId
#define THROW_LOGICAL_ERROR4(msg1, msg2, msg3, msg4)
static const int ParaCalculationStateType
static const int ParaCHAR
int ** token
index 0: token index 1: token color -1: green > 0: yellow ( termination origin solver number ) -2: re...
MessageQueueElement * getHead()
getter of head
This class has solver state to be transferred.
int send(void *bufer, int count, const int datatypeId, int dest, const int tag)
send function for standard ParaData types
static const int TagIncumbentValue
MessageQueueElement * checkElementWithTag(int tag)
check if the specified message with tag exists or nor
static ScipParaParamSet * paraParamSet
void setLock(Lock *l)
set Lock from outside.
ParaComm extension for Pthreads communication.
int getRank()
get rank of caller's thread
static const int TagTerminateRequest
virtual bool tagStringTableIsSetUpCoorectly()
check if tag string table (for debugging) set up correctly
virtual void init(int argc, char **argv)
initializer of this communicator
void setToken(int rank, int *inToken)
set received token to this communicator
static const int TagRampUp
int uTypeSend(void *bufer, const int datatypeId, int dest, int tag)
User type send for created data type.
static const int ParaLONG_LONG
static const int ParaUNSIGNED_LONG
static const int HashTableSize
size of thread table : this limits the number of threads
static __thread int localRank
local thread rank
static const int TagHardTimeLimit
void waitUntilRegistered()
wait until thread id is registered to thread table
bool waitToken(int rank)
wait token when UG runs with deterministic mode
Base class of Calculation state in a ParaSolver.
int getCount()
getter of the number of the data type elements
static const int ParaBOOL
static const int ParaInstanceType
void waitSpecTagFromSpecSource(const int source, const int tag, int *receivedTag)
wait function for a specific tag from a specific source coming from
bool passTermToken(int rank)
pass termination token from the rank to the next
static ThreadsTableElement * threadsTable[HashTableSize]
threads table: index is thread rank
virtual ~ParaCommPth()
destructor of this communicator
Lock * queueLock
Lock for synchronization.
Class of MessageQueueTableElement.
static const int ParaUNSIGNED
Base class for initial statistics collecting class.
Class for message queue element.
ConditionVariable * sentMsg
Condition variable for synchronization.
void passToken(int rank)
pass token to from the rank to the next
static const int ParaLONG
int getSource()
getter of source rank
static const int ParaLONG_DOUBLE
void * allocateMemAndCopy(const void *buffer, int count, const int datatypeId)
allocate memory and copy message
static const int ParaDOUBLE
MessageQueueElement * extarctElement(bool *sentMessage, int source, int datatypeId, int tag)
extracts a message
int comSize
communicator size : number of threads joined in this system
void lcInit(ParaParamSet *paraParamSet)
initializer for LoadCoordinator
static const int TagTaskReceived
static const int TagSolverState
static const int ParaSIGNED_CHAR
int bcast(void *buffer, int count, const int datatypeId, int root)
broadcast function for standard ParaData types
static const int TagSolution
void enqueue(std::condition_variable &sentMsg, std::mutex &queueLockMutex, bool *sentMessage, MessageQueueElement *newElement)
enqueue a message
static const int TagToken
#define THROW_LOGICAL_ERROR1(msg1)
static const int ParaSolverTerminationStateType
Lock * tokenAccessLock
lock to access token
static const int TagTrace
This class contains solver termination state which is transferred form Solver to LC.
class ParaSolverTerminationState (Solver termination state in a ParaSolver)
Base class for racing ramp-up parameter set.
ParaSysTimer timer
system timer
static const char * tagStringTable[]
tag name string table
static const int ParaUNSIGNED_CHAR
void registedAllSolvers()
notify that all solvers are registered
void setRank(int r)
setter of this thread rank
#define THROW_LOGICAL_ERROR2(msg1, msg2)
static const int ParaSolutionType
void freeMem(void *buffer, int count, const int datatypeId)
free memory
int uTypeReceive(void **bufer, const int datatypeId, int source, int tag)
User type receive for created data type.
Class that implements a lock. The class wraps around pthread_mutex_t and adds some safeguards...
Class of ThreadsTableElement.
MessageQueueTableElement ** messageQueueTable
message queue table
static const int ParaBYTE
static const int TagTerminated
int receive(void *bufer, int count, const int datatypeId, int source, const int tag)
receive function for standard ParaData types
void start(void)
start timer
static const int ParaUNSIGNED_LONG_LONG
#define TAG_TRACE(call, fromTo, sourceDest, tag)
static const int TagDiffSubproblem
int getTag()
getter of the message tag
void * getData()
getter of data
static const int ParaFLOAT
bool freeStandardTypes(MessageQueueElement *elem)
free memory
static const int TagInterruptRequest
bool tagTraceFlag
indicate if tags are traced or not
bool isEmpty()
check if the queue is empty or not
unsigned int hashCode(pthread_t tid)
get hash code from thread id
void waitMessage(std::condition_variable &sentMsg, std::mutex &queueLockMutex, bool *sentMessage)
wait for a message coming to a queue
static const int ParaTaskType
std::ostream * getOstream()
get ostream pointer
bool probe(int *source, int *tag)
probe function which waits a new message
bool * sentMessage
sent message flag for synchronization
static const int ParaSolverStateType
class ParaRacingRampUpParamSet (parameter set for racing ramp-up)
int getRank()
getter of this thread rank
bool iProbe(int *source, int *tag)
iProbe function which checks if a new message is arrived or not
ThreadsTableElement * getNext()
get next element
static const int ParaUNSIGNED_SHORT
#define ABORT_LOGICAL_ERROR2(msg1, msg2)
static const int TagCompletionOfCalculation
static const int ParaParamSetType
void copy(void *dest, const void *src, int count, int datatypeId)
copy message
static const int UG_USER_TYPE_FIRST
user defined transfer data types
static const int ParaRacingRampUpParamType
virtual const char * getTagString(int tag)
get Tag string for debugging
void solverReInit(int rank, ParaParamSet *paraParamSet)
reinitializer of a specific Solver
void solverDel(int rank)
delete Solver from this communicator
static const int TagWinner
static const int TagAckCompletion
bool getBoolParamValue(int param)
for bool parameters
void solverInit(ParaParamSet *paraParamSet)
initializer for Solvers