Class Index Cross Index Namespace Index

Class SoThreader

SoThreader TODO: put code with cloops into the compiled .cc file TODO: extend this class to handle shared object file replication
Contained in: global
Derived from: none
Derived by: none

#include "general/sothreader.hh"


public function member index:

SoThreader(const char* prtstr, int N = 4, bool loadNow = true); Constructor.
~SoThreader(); Destructor.
void* getHandle(); Get available shared object library handle handle or wait for it.
void giveHandle(void* handle); Return handle back when done.
 

Description:

automatically. That code will need to manipulate LD_LIBRARY_PATH to point to different directory, where it puts new copy of the shared object library (or libraries as a shared object lib could have dependencies on the other non-reentrant solibs). Above extension could create problems on the systems where LDAS file system is exported read only. Usage example with the CLAPACK:
 #include
 SoThreader lapack("libclapack%d.so", 4, false);
 //--------------------------------------------------------------------------------
  // Get a handle to the CLAPACK library instance
  void *handle = lapack.getHandle();
  //Find a pointer to the function to call
  int (*dgesvx_) (char *fact, char *trans, integer *n, integer * nrhs, doublereal *a, integer *lda, doublereal *af, integer *ldaf, integer *ipiv, char *equed, doublereal *r__, doublereal *c__, doublereal *b, integer *ldb, doublereal *x, integer *ldx, doublereal * rcond, doublereal *ferr, doublereal *berr, doublereal *work, integer * iwork, integer *info)
    = (int (*) (char *fact, char *trans, integer *n, integer * nrhs, doublereal *a, integer *lda, doublereal *af, integer *ldaf, integer *ipiv, char *equed, doublereal *r__, doublereal *c__, doublereal *b, integer *ldb, doublereal *x, integer *ldx, doublereal * rcond, doublereal *ferr, doublereal *berr, doublereal *work, integer * iwork, integer *info)) dlsym( handle, "dgesvx_" );
  // Exit if symbol lookup failed
  char *error;
  if ((error = dlerror()) != NULL)  {
    cerr << error << endl;
    exit(1);
  }
  // Do the processing...
  // CLAPACK library instance is held private to this thread.
  for (int i = 0; i < 1000; i++) {
    (*dgesvx_)(&fact, &trans, &n, &nrhs, a, &lda, af, &ldaf,
        ipiv, &equed, r__, c__, b, &ldb, x, &ldx, &rcond,
        ferr, berr, work, iwork, &info);
    inf |= info;
  }
  // Release CLAPACK library handle back, which makes it
  // available for the use in other threads.
  lapack.giveHandle( handle );
 


Function Member Descriptions:


SoThreader::SoThreader - Constructor.


SoThreader(const char* prtstr, int N = 4, bool loadNow = true);
Preload shared object library N times. Prints error message and exits the program if shared object loading fails.

Parameters:
ParameterDescription
const char* prtstrShared object file name template. This has to have a for of "libfoo%d.so", where "%d" will be replaced by the sprintf() function with the decimal numbers in [0-N) range. These object files has to exist in the LD_LIBRARY_PATH for this to work.
int NNumber of times to preload.
bool loadNow"false" means resolve undefined symbols as code from the dynamic library is executed or "true" means resolve all undefined now. Calls exit(1) if this cannot be done.



SoThreader::~SoThreader - Destructor.


~SoThreader();



SoThreader::getHandle - Get available shared object library handle handle or wait for it.


void* getHandle();

Return value:
void*shared object library handle.


SoThreader::giveHandle - Return handle back when done.


void giveHandle(void* handle);

Parameters:
ParameterDescription
void* handleshared object library handle.



Variable Member Descriptions:


SoThreader::handles - Shared object handles storage.

std::vector<void*> handles;

SoThreader::lock - Object instance lock.

pthread_mutex_t lock;

SoThreader::notempty - Users will wait on this for the next available handle.

pthread_cond_t notempty;