Commit 9e114485 authored by Lisa Avila's avatar Lisa Avila
Browse files

Changed ThreadCount to NumberOfThreads

parent da73b83d
......@@ -71,20 +71,20 @@ vtkMultiThreader::vtkMultiThreader()
#ifdef VTK_USE_SPROC
// Default the number of threads to be the number of available
// processors if we are using sproc()
this->ThreadCount = prctl( PR_MAXPPROCS );
this->NumberOfThreads = prctl( PR_MAXPPROCS );
#endif
#ifdef VTK_USE_PTHREADS
// Default the number of threads to be the number of available
// processors if we are using pthreads()
this->ThreadCount = sysconf( _SC_NPROCESSORS_ONLN );
this->NumberOfThreads = sysconf( _SC_NPROCESSORS_ONLN );
#endif
#ifdef _WIN32
{
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
this->ThreadCount = sysInfo.dwNumberOfProcessors;
this->NumberOfThreads = sysInfo.dwNumberOfProcessors;
}
#endif
......@@ -93,7 +93,7 @@ vtkMultiThreader::vtkMultiThreader()
#ifndef VTK_USE_PTHREADS
// If we are not multithreading, the number of threads should
// always be 1
this->ThreadCount = 1;
this->NumberOfThreads = 1;
#endif
#endif
#endif
......@@ -106,7 +106,7 @@ vtkMultiThreader::~vtkMultiThreader()
}
// Description:
// Set the user defined method that will be run on ThreadCount threads
// Set the user defined method that will be run on NumberOfThreads threads
// when SingleMethodExecute is called.
void vtkMultiThreader::SetSingleMethod( vtkThreadFunctionType f,
void *data )
......@@ -116,17 +116,17 @@ void vtkMultiThreader::SetSingleMethod( vtkThreadFunctionType f,
}
// Description:
// Set one of the user defined methods that will be run on ThreadCount
// Set one of the user defined methods that will be run on NumberOfThreads
// threads when MultipleMethodExecute is called. This method should be
// called with index = 0, 1, .., ThreadCount-1 to set up all the
// called with index = 0, 1, .., NumberOfThreads-1 to set up all the
// required user defined methods
void vtkMultiThreader::SetMultipleMethod( int index,
vtkThreadFunctionType f, void *data )
{
// You can only set the method for 0 through ThreadCount-1
if ( index >= this->ThreadCount ) {
// You can only set the method for 0 through NumberOfThreads-1
if ( index >= this->NumberOfThreads ) {
vtkErrorMacro( << "Can't set method " << index <<
" with a thread count of " << this->ThreadCount );
" with a thread count of " << this->NumberOfThreads );
}
else
{
......@@ -136,7 +136,7 @@ void vtkMultiThreader::SetMultipleMethod( int index,
}
// Description:
// Execute the method set as the SingleMethod on ThreadCount threads.
// Execute the method set as the SingleMethod on NumberOfThreads threads.
void vtkMultiThreader::SingleMethodExecute()
{
int thread_loop;
......@@ -167,17 +167,17 @@ void vtkMultiThreader::SingleMethodExecute()
#ifdef _WIN32
// Using CreateThread on a PC
//
// We want to use CreateThread to start this->ThreadCount - 1
// We want to use CreateThread to start this->NumberOfThreads - 1
// additional threads which will be used to call this->SingleMethod().
// The parent thread will also call this routine. When it is done,
// it will wait for all the children to finish.
//
// First, start up the this->ThreadCount-1 processes. Keep track
// First, start up the this->NumberOfThreads-1 processes. Keep track
// of their process ids for use later in the waitid call
for (thread_loop = 0; thread_loop < this->ThreadCount-1; thread_loop++ )
for (thread_loop = 0; thread_loop < this->NumberOfThreads-1; thread_loop++ )
{
this->ThreadInfoArray[thread_loop].UserData = this->SingleData;
this->ThreadInfoArray[thread_loop].ThreadCount = this->ThreadCount;
this->ThreadInfoArray[thread_loop].NumberOfThreads = this->NumberOfThreads;
process_id[thread_loop] =
CreateThread(NULL, 0, this->SingleMethod,
((void *)(&this->ThreadInfoArray[thread_loop])), 0, &threadId);
......@@ -188,20 +188,22 @@ void vtkMultiThreader::SingleMethodExecute()
}
// Now, the parent thread calls this->SingleMethod() itself
this->ThreadInfoArray[this->ThreadCount-1].UserData = this->SingleData;
this->ThreadInfoArray[this->ThreadCount-1].ThreadCount = this->ThreadCount;
this->ThreadInfoArray[this->NumberOfThreads-1].UserData =
this->SingleData;
this->ThreadInfoArray[this->NumberOfThreads-1].NumberOfThreads =
this->NumberOfThreads;
this->SingleMethod(
(void *)(&this->ThreadInfoArray[this->ThreadCount-1]));
(void *)(&this->ThreadInfoArray[this->NumberOfThreads-1]));
// The parent thread has finished this->SingleMethod() - so now it
// waits for each of the other processes to exit
for ( thread_loop = 0; thread_loop < this->ThreadCount-1; thread_loop++ )
for ( thread_loop = 0; thread_loop < this->NumberOfThreads-1; thread_loop++ )
{
WaitForSingleObject(process_id[thread_loop], INFINITE);
}
// close the threads
for ( thread_loop = 0; thread_loop < this->ThreadCount-1; thread_loop++ )
for ( thread_loop = 0; thread_loop < this->NumberOfThreads-1; thread_loop++ )
{
CloseHandle(process_id[thread_loop]);
}
......@@ -210,31 +212,33 @@ void vtkMultiThreader::SingleMethodExecute()
#ifdef VTK_USE_SPROC
// Using sproc() on an SGI
//
// We want to use sproc to start this->ThreadCount - 1 additional
// We want to use sproc to start this->NumberOfThreads - 1 additional
// threads which will be used to call this->SingleMethod(). The
// parent thread will also call this routine. When it is done,
// it will wait for all the children to finish.
//
// First, start up the this->ThreadCount-1 processes. Keep track
// First, start up the this->NumberOfThreads-1 processes. Keep track
// of their process ids for use later in the waitid call
for ( thread_loop = 0; thread_loop < this->ThreadCount-1; thread_loop++ )
for ( thread_loop = 0; thread_loop < this->NumberOfThreads-1; thread_loop++ )
{
this->ThreadInfoArray[thread_loop].UserData = this->SingleData;
this->ThreadInfoArray[thread_loop].ThreadCount = this->ThreadCount;
this->ThreadInfoArray[thread_loop].NumberOfThreads = this->NumberOfThreads;
process_id[thread_loop] =
sproc( this->SingleMethod, PR_SADDR,
( (void *)(&this->ThreadInfoArray[thread_loop]) ) );
}
// Now, the parent thread calls this->SingleMethod() itself
this->ThreadInfoArray[this->ThreadCount-1].UserData = this->SingleData;
this->ThreadInfoArray[this->ThreadCount-1].ThreadCount = this->ThreadCount;
this->ThreadInfoArray[this->NumberOfThreads-1].UserData =
this->SingleData;
this->ThreadInfoArray[this->NumberOfThreads-1].NumberOfThreads =
this->NumberOfThreads;
this->SingleMethod(
(void *)(&this->ThreadInfoArray[this->ThreadCount-1]) );
(void *)(&this->ThreadInfoArray[this->NumberOfThreads-1]) );
// The parent thread has finished this->SingleMethod() - so now it
// waits for each of the other processes to exit
for ( thread_loop = 0; thread_loop < this->ThreadCount-1; thread_loop++ )
for ( thread_loop = 0; thread_loop < this->NumberOfThreads-1; thread_loop++ )
{
waitid( P_PID, (id_t) process_id[thread_loop], &info_ptr, WEXITED );
}
......@@ -243,37 +247,39 @@ void vtkMultiThreader::SingleMethodExecute()
#ifdef VTK_USE_PTHREADS
// Using POSIX threads
//
// We want to use pthread_create to start this->ThreadCount - 1 additional
// We want to use pthread_create to start this->NumberOfThreads-1 additional
// threads which will be used to call this->SingleMethod(). The
// parent thread will also call this routine. When it is done,
// it will wait for all the children to finish.
//
// First, start up the this->ThreadCount-1 processes. Keep track
// First, start up the this->NumberOfThreads-1 processes. Keep track
// of their process ids for use later in the pthread_join call
pthread_attr_t attr;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
pthread_attr_init(&attr);
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
for ( thread_loop = 0; thread_loop < this->ThreadCount-1; thread_loop++ )
for ( thread_loop = 0; thread_loop < this->NumberOfThreads-1; thread_loop++ )
{
this->ThreadInfoArray[thread_loop].UserData = this->SingleData;
this->ThreadInfoArray[thread_loop].ThreadCount = this->ThreadCount;
this->ThreadInfoArray[thread_loop].NumberOfThreads = this->NumberOfThreads;
pthread_create( &(process_id[thread_loop]),
&attr, this->SingleMethod,
( (void *)(&this->ThreadInfoArray[thread_loop]) ) );
}
// Now, the parent thread calls this->SingleMethod() itself
this->ThreadInfoArray[this->ThreadCount-1].UserData = this->SingleData;
this->ThreadInfoArray[this->ThreadCount-1].ThreadCount = this->ThreadCount;
this->ThreadInfoArray[this->NumberOfThreads-1].UserData =
this->SingleData;
this->ThreadInfoArray[this->NumberOfThreads-1].NumberOfThreads =
this->NumberOfThreads;
this->SingleMethod(
(void *)(&this->ThreadInfoArray[this->ThreadCount - 1]) );
(void *)(&this->ThreadInfoArray[this->NumberOfThreads - 1]) );
// The parent thread has finished this->SingleMethod() - so now it
// waits for each of the other processes to exit
for ( thread_loop = 0; thread_loop < this->ThreadCount-1; thread_loop++ )
for ( thread_loop = 0; thread_loop < this->NumberOfThreads-1; thread_loop++ )
{
pthread_join( process_id[thread_loop], NULL );
}
......@@ -284,7 +290,7 @@ pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
#ifndef VTK_USE_PTHREADS
// There is no multi threading, so there is only one thread.
this->ThreadInfoArray[0].UserData = this->SingleData;
this->ThreadInfoArray[0].ThreadCount = this->ThreadCount;
this->ThreadInfoArray[0].NumberOfThreads = this->NumberOfThreads;
this->SingleMethod( (void *)(&this->ThreadInfoArray[0]) );
#endif
#endif
......@@ -310,7 +316,7 @@ void vtkMultiThreader::MultipleMethodExecute()
#endif
for ( thread_loop = 0; thread_loop < this->ThreadCount; thread_loop++ )
for ( thread_loop = 0; thread_loop < this->NumberOfThreads; thread_loop++ )
if ( this->MultipleMethod[thread_loop] == (void *)NULL)
{
vtkErrorMacro( << "No multiple method set for: " << thread_loop );
......@@ -323,19 +329,19 @@ void vtkMultiThreader::MultipleMethodExecute()
#ifdef _WIN32
// Using CreateThread on a PC
//
// We want to use CreateThread to start this->ThreadCount - 1
// additional threads which will be used to call the ThreadCount-1
// We want to use CreateThread to start this->NumberOfThreads - 1
// additional threads which will be used to call the NumberOfThreads-1
// methods defined in this->MultipleMethods[](). The parent thread
// will call this->MultipleMethods[ThreadCount-1](). When it is done,
// will call this->MultipleMethods[NumberOfThreads-1](). When it is done,
// it will wait for all the children to finish.
//
// First, start up the this->ThreadCount-1 processes. Keep track
// First, start up the this->NumberOfThreads-1 processes. Keep track
// of their process ids for use later in the waitid call
for ( thread_loop = 0; thread_loop < this->ThreadCount-1; thread_loop++ )
for ( thread_loop = 0; thread_loop < this->NumberOfThreads-1; thread_loop++ )
{
this->ThreadInfoArray[thread_loop].UserData =
this->MultipleData[thread_loop];
this->ThreadInfoArray[thread_loop].ThreadCount = this->ThreadCount;
this->ThreadInfoArray[thread_loop].NumberOfThreads = this->NumberOfThreads;
process_id[thread_loop] =
CreateThread(NULL, 0, this->MultipleMethod[thread_loop],
((void *)(&this->ThreadInfoArray[thread_loop])), 0, &threadId);
......@@ -346,22 +352,23 @@ void vtkMultiThreader::MultipleMethodExecute()
}
// Now, the parent thread calls the last method itself
this->ThreadInfoArray[this->ThreadCount-1].UserData =
this->MultipleData[this->ThreadCount-1];
this->ThreadInfoArray[this->ThreadCount-1].ThreadCount = this->ThreadCount;
(this->MultipleMethod[this->ThreadCount-1])(
(void *)(&this->ThreadInfoArray[this->ThreadCount-1]) );
this->ThreadInfoArray[this->NumberOfThreads-1].UserData =
this->MultipleData[this->NumberOfThreads-1];
this->ThreadInfoArray[this->NumberOfThreads-1].NumberOfThreads =
this->NumberOfThreads;
(this->MultipleMethod[this->NumberOfThreads-1])(
(void *)(&this->ThreadInfoArray[this->NumberOfThreads-1]) );
// The parent thread has finished its method - so now it
// waits for each of the other processes (created with sproc) to
// exit
for ( thread_loop = 0; thread_loop < this->ThreadCount-1; thread_loop++ )
for ( thread_loop = 0; thread_loop < this->NumberOfThreads-1; thread_loop++ )
{
WaitForSingleObject(process_id[thread_loop], INFINITE);
}
// close the threads
for ( thread_loop = 0; thread_loop < this->ThreadCount-1; thread_loop++ )
for ( thread_loop = 0; thread_loop < this->NumberOfThreads-1; thread_loop++ )
{
CloseHandle(process_id[thread_loop]);
}
......@@ -370,35 +377,36 @@ void vtkMultiThreader::MultipleMethodExecute()
#ifdef VTK_USE_SPROC
// Using sproc() on an SGI
//
// We want to use sproc to start this->ThreadCount - 1 additional
// threads which will be used to call the ThreadCount-1 methods
// We want to use sproc to start this->NumberOfThreads - 1 additional
// threads which will be used to call the NumberOfThreads-1 methods
// defined in this->MultipleMethods[](). The parent thread
// will call this->MultipleMethods[ThreadCount-1](). When it is done,
// will call this->MultipleMethods[NumberOfThreads-1](). When it is done,
// it will wait for all the children to finish.
//
// First, start up the this->ThreadCount-1 processes. Keep track
// First, start up the this->NumberOfThreads-1 processes. Keep track
// of their process ids for use later in the waitid call
for ( thread_loop = 0; thread_loop < this->ThreadCount-1; thread_loop++ )
for ( thread_loop = 0; thread_loop < this->NumberOfThreads-1; thread_loop++ )
{
this->ThreadInfoArray[thread_loop].UserData =
this->MultipleData[thread_loop];
this->ThreadInfoArray[thread_loop].ThreadCount = this->ThreadCount;
this->ThreadInfoArray[thread_loop].NumberOfThreads = this->NumberOfThreads;
process_id[thread_loop] =
sproc( this->MultipleMethod[thread_loop], PR_SADDR,
( (void *)(&this->ThreadInfoArray[thread_loop]) ) );
}
// Now, the parent thread calls the last method itself
this->ThreadInfoArray[this->ThreadCount-1].UserData =
this->MultipleData[this->ThreadCount-1];
this->ThreadInfoArray[this->ThreadCount-1].ThreadCount = this->ThreadCount;
(this->MultipleMethod[this->ThreadCount-1])(
(void *)(&this->ThreadInfoArray[this->ThreadCount-1]) );
this->ThreadInfoArray[this->NumberOfThreads-1].UserData =
this->MultipleData[this->NumberOfThreads-1];
this->ThreadInfoArray[this->NumberOfThreads-1].NumberOfThreads =
this->NumberOfThreads;
(this->MultipleMethod[this->NumberOfThreads-1])(
(void *)(&this->ThreadInfoArray[this->NumberOfThreads-1]) );
// The parent thread has finished its method - so now it
// waits for each of the other processes (created with sproc) to
// exit
for ( thread_loop = 0; thread_loop < this->ThreadCount-1; thread_loop++ )
for ( thread_loop = 0; thread_loop < this->NumberOfThreads-1; thread_loop++ )
{
waitid( P_PID, (id_t) process_id[thread_loop], &info_ptr, WEXITED );
}
......@@ -407,34 +415,36 @@ void vtkMultiThreader::MultipleMethodExecute()
#ifdef VTK_USE_PTHREADS
// Using POSIX threads
//
// We want to use pthread_create to start this->ThreadCount - 1 additional
// threads which will be used to call the ThreadCount-1 methods
// We want to use pthread_create to start this->NumberOfThreads - 1
// additional
// threads which will be used to call the NumberOfThreads-1 methods
// defined in this->MultipleMethods[](). The parent thread
// will call this->MultipleMethods[ThreadCount-1](). When it is done,
// will call this->MultipleMethods[NumberOfThreads-1](). When it is done,
// it will wait for all the children to finish.
//
// First, start up the this->ThreadCount-1 processes. Keep track
// First, start up the this->NumberOfThreads-1 processes. Keep track
// of their process ids for use later in the pthread_join call
for ( thread_loop = 0; thread_loop < this->ThreadCount-1; thread_loop++ )
for ( thread_loop = 0; thread_loop < this->NumberOfThreads-1; thread_loop++ )
{
this->ThreadInfoArray[thread_loop].UserData =
this->MultipleData[thread_loop];
this->ThreadInfoArray[thread_loop].ThreadCount = this->ThreadCount;
this->ThreadInfoArray[thread_loop].NumberOfThreads = this->NumberOfThreads;
pthread_create( &(process_id[thread_loop]),
NULL, this->MultipleMethod[thread_loop],
( (void *)(&this->ThreadInfoArray[thread_loop]) ) );
}
// Now, the parent thread calls the last method itself
this->ThreadInfoArray[this->ThreadCount-1].UserData =
this->MultipleData[this->ThreadCount-1];
this->ThreadInfoArray[this->ThreadCount-1].ThreadCount = this->ThreadCount;
(this->MultipleMethod[this->ThreadCount-1])(
(void *)(&this->ThreadInfoArray[this->ThreadCount - 1]) );
this->ThreadInfoArray[this->NumberOfThreads-1].UserData =
this->MultipleData[this->NumberOfThreads-1];
this->ThreadInfoArray[this->NumberOfThreads-1].NumberOfThreads =
this->NumberOfThreads;
(this->MultipleMethod[this->NumberOfThreads-1])(
(void *)(&this->ThreadInfoArray[this->NumberOfThreads - 1]) );
// The parent thread has finished its method - so now it
// waits for each of the other processes to exit
for ( thread_loop = 0; thread_loop < this->ThreadCount-1; thread_loop++ )
for ( thread_loop = 0; thread_loop < this->NumberOfThreads-1; thread_loop++ )
{
pthread_join( process_id[thread_loop], NULL );
}
......@@ -445,7 +455,7 @@ void vtkMultiThreader::MultipleMethodExecute()
#ifndef VTK_USE_PTHREADS
// There is no multi threading, so there is only one thread.
this->ThreadInfoArray[0].UserData = this->MultipleData[0];
this->ThreadInfoArray[0].ThreadCount = this->ThreadCount;
this->ThreadInfoArray[0].NumberOfThreads = this->NumberOfThreads;
(this->MultipleMethod[0])( (void *)(&this->ThreadInfoArray[0]) );
#endif
#endif
......@@ -457,6 +467,6 @@ void vtkMultiThreader::MultipleMethodExecute()
void vtkMultiThreader::PrintSelf(ostream& os, vtkIndent indent)
{
os << indent << "Thread Count: " << this->ThreadCount << "\n";
os << indent << "Thread Count: " << this->NumberOfThreads << "\n";
}
......@@ -117,14 +117,14 @@ typedef void (*vtkThreadFunctionType)(void *);
// MultipleMethod that is called during SingleMethodExecute or
// MultipleMethodExecute. It is passed in as a void *, and it is
// up to the method to cast correctly and extract the information.
// The ThreadID is a number between 0 and ThreadCount-1 that indicates
// the id of this thread. The ThreadCount is this->ThreadCount.
// The ThreadID is a number between 0 and NumberOfThreads-1 that indicates
// the id of this thread. The NumberOfThreads is this->NumberOfThreads.
// The UserData is obtained from the SetSingleMethod or SetMultipleMethod
// call.
struct ThreadInfoStruct
{
int ThreadID;
int ThreadCount;
int NumberOfThreads;
void *UserData;
};
......@@ -143,8 +143,8 @@ public:
// It will be clamped to the range 1 - VTK_MAX_THREADS, so the
// caller of this method should check that the requested number
// of threads was accepted.
vtkSetClampMacro( ThreadCount, int, 1, VTK_MAX_THREADS );
vtkGetMacro( ThreadCount, int );
vtkSetClampMacro( NumberOfThreads, int, 1, VTK_MAX_THREADS );
vtkGetMacro( NumberOfThreads, int );
// These methods are excluded from Tcl wrapping 1) because the
// wrapper barfs on them and 2) because they really shouldn't be
......@@ -153,13 +153,13 @@ public:
// Description:
// Execute the SingleMethod (as define by SetSingleMethod) using
// this->ThreadCount threads.
// this->NumberOfThreads threads.
void SingleMethodExecute();
// Description:
// Execute the MultipleMethods (as define by calling SetMultipleMethod
// for each of the required this->ThreadCount methods) using
// this->ThreadCount threads.
// for each of the required this->NumberOfThreads methods) using
// this->NumberOfThreads threads.
void MultipleMethodExecute();
// Description:
......@@ -178,7 +178,7 @@ public:
protected:
// The number of threads to use
int ThreadCount;
int NumberOfThreads;
// An array of thread info containing a thread id
// (0, 1, 2, .. VTK_MAX_THREADS-1), the thread count, and a pointer
......
......@@ -219,7 +219,7 @@ vtkNormalEncoder::vtkNormalEncoder()
this->GradientMagnitudeRange[0] = 0.0;
this->GradientMagnitudeRange[1] = 256.0;
this->IndexTableInitialized = 0;
this->ThreadCount = this->Threader.GetThreadCount();
this->NumberOfThreads = this->Threader.GetNumberOfThreads();
for ( i = 0; i < 256; i++ )
this->GradientMagnitudeTable[i] = this->GradientMagnitudeRange[0] +
......@@ -463,7 +463,7 @@ void vtkNormalEncoder::UpdateNormals( )
memcpy( this->ScalarInputSize, scalar_input_size, 3 * sizeof(int) );
memcpy( this->ScalarInputAspect, scalar_input_aspect, 3 * sizeof(float) );
this->Threader.SetThreadCount( this->ThreadCount );
this->Threader.SetNumberOfThreads( this->NumberOfThreads );
this->Threader.SetSingleMethod( SwitchOnDataType,
(vtkObject *)this );
......@@ -485,7 +485,7 @@ VTK_THREAD_RETURN_TYPE SwitchOnDataType( void *arg )
char *data_type;
thread_id = ((ThreadInfoStruct *)(arg))->ThreadID;
thread_count = ((ThreadInfoStruct *)(arg))->ThreadCount;
thread_count = ((ThreadInfoStruct *)(arg))->NumberOfThreads;
encoder = (vtkNormalEncoder *)(((ThreadInfoStruct *)(arg))->UserData);
// Find the data type of the ScalarInput and call the correct
......
......@@ -134,8 +134,8 @@ public:
// Description:
// Get/Set the number of threads to create when encoding normals
vtkSetClampMacro( ThreadCount, int, 1, VTK_MAX_THREADS );
vtkGetMacro( ThreadCount, int );
vtkSetClampMacro( NumberOfThreads, int, 1, VTK_MAX_THREADS );
vtkGetMacro( NumberOfThreads, int );
// These variables should be protected but are being
// made public to be accessible to the templated function.
......@@ -189,7 +189,7 @@ protected:
void InitializeIndexTable( void );
// The number of threads to use when encoding normals
int ThreadCount;
int NumberOfThreads;
vtkMultiThreader Threader;
friend VTK_THREAD_RETURN_TYPE SwitchOnDataType( void *arg );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment