Ejemplo n.º 1
0
const char* CppSQLite3Table::fieldName(int nCol)
{
	checkResults();

	if (nCol < 0 || nCol > mnCols-1)
	{
		throw CppSQLite3Exception(CPPSQLITE_ERROR,"Invalid field index requested",DONT_DELETE_MSG);
	}

	return mpaszResults[nCol];
}
Ejemplo n.º 2
0
void show_sched_param(pthread_attr_t *a) {
	int rc = 0;
	struct sched_param param;

	rc = mythread_attr_getschedparam(a, &param);
	checkResults("pthread_attr_getschedparam()\n", rc);

	printf("param.sched_priority = %d\n",
			param.__sched_priority);
	return;
}
Ejemplo n.º 3
0
void *theThread(void *parm)
{
   int               rc;
   threadSpecific_data_t    *gData;
   printf("Thread %.8x %.8x: Entered\n", pthread_self());
   gData = (threadSpecific_data_t *)parm;
   rc = pthread_setspecific(threadSpecificKey, gData);
   checkResults("pthread_setspecific()\n", rc);
   foo();
   return NULL;
}
void *theThread(void *parm)
{
	int   rc;
	rc = pthread_mutex_lock(&mutex);
	printf("Thread %u: Entered\n",(unsigned int ) pthread_self());
	checkResults("pthread_mutex_lock()\n", rc);

	/********** Critical Section *******************/
	printf("Thread %u: Start critical section, holding lock\n",(unsigned int ) pthread_self());

	/* Access to shared data goes here */
	sharedData++; 
	sharedData2--;
	printf("Thread %u: End critical section, release lock\n", (unsigned int )pthread_self());

	/********** Critical Section *******************/
	rc = pthread_mutex_unlock(&mutex);
	checkResults("pthread_mutex_unlock()\n", rc);
	return NULL;
}
Ejemplo n.º 5
0
const char* CppSQLite3Table::fieldValue(int nField)
{
	checkResults();

	if (nField < 0 || nField > mnCols-1)
	{
		IwError(("Invalid field index requested"));
	}

	int nIndex = (mnCurrentRow*mnCols) + mnCols + nField;
	return mpaszResults[nIndex];
}
Ejemplo n.º 6
0
const char* CppSQLite3Table::fieldValue(int nField)
{
	checkResults();

	if (nField < 0 || nField > mnCols-1)
	{
		throw CppSQLite3Exception(CPPSQLITE_ERROR,"Invalid field index requested",DONT_DELETE_MSG);
	}

	int nIndex = (mnCurrentRow*mnCols) + mnCols + nField;
	return mpaszResults[nIndex];
}
Ejemplo n.º 7
0
void CppSQLite3Table::setRow(int nRow)
{
	checkResults();

	if (nRow < 0 || nRow > mnRows-1)
	{
		throw CppSQLite3Exception(CPPSQLITE_ERROR,
								"Invalid row index requested",
								DONT_DELETE_MSG);
	}

	mnCurrentRow = nRow;
}
int main(int argc, char **argv)
{
	int                   rc=0;
	int                   i;
	pthread_t             threadid[NTHREADS];

	printf("Enter Testcase - %s\n", argv[0]);

	printf("Create %d threads\n", NTHREADS);
	for(i=0; i<NTHREADS; ++i) {
	  	rc = pthread_create(&threadid[i], NULL, threadfunc, NULL);
	  	checkResults("pthread_create()\n", rc);
	}

	sleep(5);  /* Sleep is not a very robust way to serialize threads */
	rc = pthread_mutex_lock(&mutex);
	checkResults("pthread_mutex_lock()\n", rc);

	/* The condition has occured. Set the flag and wake up any waiting threads */
	conditionMet = 1;
	printf("Wake up all waiting threads...\n");
	rc = pthread_cond_broadcast(&cond);
	checkResults("pthread_cond_broadcast()\n", rc);

	rc = pthread_mutex_unlock(&mutex);
	checkResults("pthread_mutex_unlock()\n", rc);

	printf("Wait for threads and cleanup\n");
	for (i=0; i<NTHREADS; ++i) {
	  	rc = pthread_join(threadid[i], NULL);
	  	checkResults("pthread_join()\n", rc);
	}

	pthread_cond_destroy(&cond);
	pthread_mutex_destroy(&mutex);

	printf("Main completed\n");
	return 0;
}
Ejemplo n.º 9
0
void *threadfunc(void *parm)
{
  int           rc;

  while (1) {
    /* Usually worker threads will loop on these operations */
    rc = pthread_mutex_lock(&g_mutex);
    checkResults("pthread_mutex_lock()\n", rc);

    while (not workToDo) {
      printf("Thread blocked\n");
      rc = pthread_cond_wait(&g_cond, &g_mutex);
      checkResults("pthread_cond_wait()\n", rc);
    }
    printf("Thread awake, finish work!\n");
    /* Under protection of the lock, complete or remove the work     */
    /* from whatever worker queue we have. Here its simply a flag    */
    workToDo = 0;

    rc = pthread_mutex_unlock(&g_mutex);
    checkResults("pthread_mutex_lock()\n", rc);
  }
  return NULL;
}
Ejemplo n.º 10
0
const char* CppSQLite3Table::fieldValue(const char* szField)
{
	checkResults();

	if (szField)
	{
		for (int nField = 0; nField < mnCols; nField++)
		{
			if (strcmp(szField, mpaszResults[nField]) == 0)
			{
				int nIndex = (mnCurrentRow*mnCols) + mnCols + nField;
				return mpaszResults[nIndex];
			}
		}
	}

	throw CppSQLite3Exception(CPPSQLITE_ERROR,"Invalid field name requested",DONT_DELETE_MSG);
}
Ejemplo n.º 11
0
const char* CppSQLite3Table::fieldValue(const char* szField)
{
	checkResults();

	if (szField)
	{
		for (int nField = 0; nField < mnCols; nField++)
		{
			if (strcmp(szField, mpaszResults[nField]) == 0)
			{
				int nIndex = (mnCurrentRow*mnCols) + mnCols + nField;
				return mpaszResults[nIndex];
			}
		}
	}

	IwError(("Invalid field name requested"));
	return 0;
}
Ejemplo n.º 12
0
bool CppSQLite3Table::fieldIsNull(int nField)
{
	checkResults();
	return (fieldValue(nField) == 0);
}
Ejemplo n.º 13
0
int CppSQLite3Table::numRows()
{
	checkResults();
	return mnRows;
}
Ejemplo n.º 14
0
int CppSQLite3Table::numFields()
{
	checkResults();
	return mnCols;
}
int main (int argc,char * argv[])
{

    pthread_t       *threads;
    pthread_attr_t  pta;
    int             iteration,THREADS,ret_count;
    char 		* CLASS;

    double          time_start, time_end;
    struct          timeval tv;
    struct          timezone tz;

    int counter;
    printf("\n\t\t Objective : To compute the minimum of a list of numbers using mutex. \n ");

    if( argc != 3 )                                                       // check command line arguments
    {
        printf("\t\t Very Few Arguments\n ");
        printf("\t\t Syntax : exec <NumElements> <Threads>\n");
        exit(-1);
    }												// user input
    else {
        NumElements =atoi( argv[1]);
        THREADS = atoi(argv[2]);
    }

    NumThreads = THREADS;
    printf("\n\t\t Array Size  :  %ld",NumElements);
    printf("\n\t\t Threads     :  %d",NumThreads);
    printf("\n");

    if (NumThreads < 1 )
    {
        printf("\n Number of threads must be greater than zero. Aborting ...\n");
        return 0;
    }

    if ((NumThreads != 1) && (NumThreads != 2) && (NumThreads != 4) && (NumThreads != 8))
    {
        printf("\n Number of Threads must be 1 or 2 or 4 or 8. Aborting ...\n");
        return 0;
    }

    if ( ( NumElements % NumThreads ) != 0 )
    {
        printf("\n Number of threads not a factor of Integer List size. Aborting.\n");
        return 0 ;
    }


    partial_list_size = NumElements / NumThreads;                                 // define partial size for each thread

    list = (long int *)malloc(sizeof(long int) * NumElements);


    for(counter = 0 ; counter < NumElements ; counter++)
    {
        srand48((unsigned int)NumElements);							// random number generation
        list[counter] = (rand()%1000)+1.0;
    }

    threads = (pthread_t *)malloc(sizeof(pthread_t)*NumThreads);

    minimum_value = list[0];

    ret_count=pthread_mutex_init(&minimum_value_lock, NULL);
    checkResults("pthread_mutex_init()\n", ret_count);


    ret_count=pthread_attr_init(&pta);
    checkResults("pthread_attr_init()\n", ret_count);

    pthread_attr_setscope(&pta,PTHREAD_SCOPE_SYSTEM);

    gettimeofday(&tv, &tz);
    time_start = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;


    for(counter = 0 ; counter < NumThreads ; counter++)
    {
        ret_count=pthread_create(&threads[counter],&pta,(void *(*) (void *)) find_min_rwlock,(void *) (counter+1));     // call find_min_rwlock function
        checkResults("pthread_create()\n", ret_count);
    }

    gettimeofday(&tv, &tz);
    time_end = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;



    for(counter = 0 ; counter < NumThreads ; counter++)
    {
        ret_count=pthread_join(threads[counter],NULL);
        checkResults("pthread_join()\n", ret_count);
    }
    ret_count=pthread_attr_destroy(&pta);
    checkResults("pthread_attr_destroy()\n", ret_count);

    printf("\n\t\t..........................................................................\n");
    printf("\n\t\t Minimum Value found in the Integer list     :  %d",minimum_value);
    printf("\n\t\t Time Taken in Seconds  (T)                  :  %lf Seconds",( time_end - time_start));
    printf("\n\t\t..........................................................................\n");


    free(list);
    free(threads);
    return 0;

}
Ejemplo n.º 16
0
int main(int argc, char *argv[]) {

  int i;

#ifdef EPETRA_MPI
  // Initialize MPI
  MPI_Init(&argc,&argv);
  Epetra_MpiComm comm(MPI_COMM_WORLD);
#else
  Epetra_SerialComm comm;
#endif

  // Uncomment to debug in parallel int tmp; if (comm.MyPID()==0) cin >> tmp; comm.Barrier();

  bool verbose = false;
  bool veryVerbose = false;

  // Check if we should print results to standard out
  if (argc>1) if (argv[1][0]=='-' && argv[1][1]=='v') verbose = true;

  if (!verbose) comm.SetTracebackMode(0); // This should shut down any error traceback reporting

  if (verbose) cout << comm << endl << flush;

  bool verbose1 = verbose;
  if (verbose) verbose = (comm.MyPID()==0);

  int nx = 4;
  int ny = comm.NumProc()*nx; // Scale y grid with number of processors
  
  // Create funky stencil to make sure the matrix is non-symmetric (transpose non-trivial):

  // (i-1,j-1) (i-1,j  )
  // (i  ,j-1) (i  ,j  ) (i  ,j+1)
  // (i+1,j-1) (i+1,j  )
  
  int npoints = 2;

  int xoff[] = {-1,  0,  1, -1,  0,  1,  0};
  int yoff[] = {-1, -1, -1,  0,  0,  0,  1};

  Epetra_Map * map;
  Epetra_CrsMatrix * A;
  Epetra_Vector * x, * b, * xexact;
	
  Trilinos_Util_GenerateCrsProblem(nx, ny, npoints, xoff, yoff, comm, map, A, x, b, xexact);

  if (verbose) 
    cout << "npoints = " << npoints << " nx = " << nx << " ny = " << ny  << endl ; 

  if (verbose && nx<6 ) {
    cout << *A << endl;
    cout << "B       = " << endl << *b << endl;
  }
  // Construct linear problem object
  
  Epetra_LinearProblem origProblem(A, x, b);
  Epetra_LinearProblem *redistProblem;
  
  Epetra_Time timer(comm);
  
  // Construct redistor object, use all processors and replicate full problem on each

  double start = timer.ElapsedTime();
  Epetra_LinearProblemRedistor redistor(&origProblem, comm.NumProc(), true);
  if (verbose) cout << "\nTime to construct redistor  = " 
		    << timer.ElapsedTime() - start << endl;

  bool ConstructTranspose = true; 
  bool MakeDataContiguous = true;
  
  start = timer.ElapsedTime();
  redistor.CreateRedistProblem(ConstructTranspose, MakeDataContiguous, redistProblem);
  if (verbose) cout << "\nTime to create redistributed problem = " 
		    << timer.ElapsedTime() - start << endl;
  
  
  // Now test output of redistor by performing matvecs

  int ierr = 0;
  ierr += checkResults( ConstructTranspose, &redistor, &origProblem, 
			redistProblem, verbose);
  
  
  // Now change values in original rhs and test update facility of redistor
  // Multiply b by 2
  
  double Value = 2.0;
  
  b->Scale(Value); // b = 2*b
  
  redistor.UpdateRedistRHS(b);
  if (verbose) cout << "\nTime to update redistributed RHS  = " 
		    << timer.ElapsedTime() - start << endl;
  
  ierr += checkResults( ConstructTranspose, &redistor, 
			&origProblem, redistProblem, verbose);
 
  // Now change values in original matrix and test update facility of redistor

#define  CREATE_CONST_MATRIX
#ifdef CREATE_CONST_MATRIX
  //  The easiest way that I could find to change the matrix without EPETRA_CHK_ERRs
  A->PutScalar(13.0); 
#else 

  //  This has no effect on matrices, such as when nx = 4, that have no 
  //  diagonal entries.  However, it does cause many EPETRA_CHK_ERR prints.

  // Add 2 to the diagonal of each row 
  for (i=0; i< A->NumMyRows(); i++)  {
  //  for (i=0; i < 1; i++)
    cout << " i = " << i ; 
    A->SumIntoMyValues(i, 1, &Value, &i);
  }
#endif  
  
  
  start = timer.ElapsedTime();
  redistor.UpdateRedistProblemValues(&origProblem);
  if (verbose) cout << "\nTime to update redistributed problem  = " 
		    << timer.ElapsedTime() - start << endl;
  
  ierr += checkResults(ConstructTranspose, &redistor, &origProblem, redistProblem, verbose);
  
  delete A;
  delete b;
  delete x;
  delete xexact;
  delete map;
  
  
#ifdef EPETRA_MPI
  MPI_Finalize();
#endif

  return ierr;
}
// EXCEPTIONS: CProcessFailure
void CPCPATRDllProcess::processANAFile(CProcessStatus& status)
{
  CModelFilesSet* pSourceMFS = status.getInputMFS();
  ASSERTX(pSourceMFS);
  CModelFilesSet* pTargetMFS = status.getOutputMFS(); // may be null

  try
	{
	  IPatrParser *pPatr;
	  CLSID clsid;
	  HRESULT hr;

#ifndef hab245
	  CString sBase;
	  sBase.Format(_T("%s%d"), (LPCTSTR)getTempFileNameBase(status), status.m_iProcNumber);
#else // hab245
	  CString sBase = getTempFileNameBase(status);
#endif // hab245
	  m_sOutPath = status.makeTempPath(sBase,	_T(".ana") );
	  m_sLOGPath = status.makeTempPath(sBase,	_T(".log") );

	  m_sInPath = status.sANAPath;
	  m_sOutPath.deleteFile();
	  m_sLOGPath.deleteFile();

	  hr = CoInitialize(NULL);
#ifndef hab245
	  checkResults(hr, _T("coinitialize"), (IPatrParser *)NULL);
	  hr = CLSIDFromProgID(L"SIL.CARLA.PatrParser.1", &clsid);
	  checkResults(hr, _T("get CLSID"), (IPatrParser *)NULL);
	  hr = CoCreateInstance(clsid, NULL, CLSCTX_ALL,
				IID_IPatrParser, (void **) &pPatr);
	  checkResults(hr, _T("do CoCreateInstance"), (IPatrParser *)NULL);
	  CString s = m_sLOGPath.getQuotedPath();
	  CString sLogFile = s.Mid(1, s.GetLength()-2);
	  hr = pPatr->OpenLog(sLogFile.AllocSysString());
	  checkResults(hr, _T("set log file"), (IPatrParser *)NULL);
	  hr = pPatr->Clear();
	  checkResults(hr, _T("clear"), pPatr);
	  hr = pPatr->put_CommentChar(status.getInputMFS()->getCommentChar());
	  checkResults(hr, _T("set comment character"), pPatr);
	  hr = pPatr->put_AmplePropertyIsFeature(m_bAmplePropertyIsFeature);
	  checkResults(hr, _T("set AmplePropertyIsFeature"), pPatr);
	  hr = pPatr->put_PromoteDefaultAtoms(m_bPromoteDefaultAtomicValues);
	  checkResults(hr, _T("set PromoteDefaultAtoms"), pPatr);
	  hr = pPatr->put_Failures(m_bShowFailures);
	  checkResults(hr, _T("set Failures"), pPatr);
	  hr = pPatr->put_DisplayFeatures(m_bDisplayFeatures);
	  checkResults(hr, _T("set DisplayFeatures"), pPatr);
	  hr = pPatr->put_TopFeatureOnly(!m_bAllFeatures);
	  checkResults(hr, _T("set TopFeatureOnly"), pPatr);
	  hr = pPatr->put_Gloss(m_bDisplayGloss);
	  checkResults(hr, _T("set Gloss"), pPatr);
	  hr = pPatr->put_TrimEmptyFeatures(m_bTrimEmptyFeatures);
	  checkResults(hr, _T("set TrimEmptyFeatures"), pPatr);
	  hr = pPatr->put_Unification(m_bPerformUnification);
	  checkResults(hr, _T("set Unification"), pPatr);
	  hr = pPatr->put_WriteAmpleParses(m_bWriteAmpleParses);
	  checkResults(hr, _T("set WriteAmpleParses"), pPatr);
	  hr = pPatr->put_MaxAmbiguity(m_uiMaxAmbiguities);
	  checkResults(hr, _T("set MaxAmbiguity"), pPatr);
#ifndef rde273
	  hr = pPatr->put_CodePage(GetCSAcp());
#endif  // rde273
	  hr = pPatr->put_SentenceFinalPunctuation(
				 m_sSentenceFinalPunctuation.AllocSysString());
	  checkResults(hr, _T("set SentenceFinalPunctuation"), pPatr);
	  hr = pPatr->put_TimeLimit(m_uiTimeLimit);
	  checkResults(hr, _T("set TimeLimit"), pPatr);
	  hr = pPatr->put_TreeDisplay(m_iTreeDisplayFormat);
	  checkResults(hr, _T("set TreeDisplay"), pPatr);
	  hr = pPatr->put_FlatFeatureDisplay(m_bFlatFeatureDisplay);
	  checkResults(hr, _T("set FlatFeatureDisplay"), pPatr);

#ifndef hab262
	  if (m_iRootGlossSetting > 0)
	m_iRootGlossSetting++;	// need to adjust value to get correct setting
	  hr = pPatr->put_RootGlossFeature(m_iRootGlossSetting);
	  if (m_iRootGlossSetting > 0)
	m_iRootGlossSetting--;	// adjust the value back
	  checkResults(hr, _T("set RootGlossFeature"), pPatr);
#endif // hab262
	  hr = pPatr->LoadGrammarFile(m_sGrammarFileName.AllocSysString());
	  checkResults(hr, _T("load grammar file.\nSee Log File."), pPatr);
	  s = m_sOutPath.getQuotedPath();;
	  CString sOutFile = s.Mid(1, s.GetLength()-2);
	  hr = pPatr->DisambiguateAnaFile(m_sInPath.getShortPath().AllocSysString(),
					  sOutFile.AllocSysString());
	  checkResults(hr, _T("disambiguate ANA file"), pPatr);
	  hr = pPatr->CloseLog();
	  checkResults(hr, _T("close log file"), pPatr);
#else // hab245

	  checkResults(hr, _T("coinitialize"));
	  hr = CLSIDFromProgID(L"SIL.CARLA.PatrParser.1", &clsid);
	  checkResults(hr, "get CLSID");
	  hr = CoCreateInstance(clsid, NULL, CLSCTX_ALL,
				IID_IPatrParser, (void **) &pPatr);
	  checkResults(hr, "do CoCreateInstance");
	  hr = pPatr->Clear();
	  checkResults(hr, "clear");
	  hr = pPatr->put_CommentChar(status.getInputMFS()->getCommentChar());
	  checkResults(hr, "set comment character");
	  hr = pPatr->put_AmplePropertyIsFeature(m_bAmplePropertyIsFeature);
	  checkResults(hr, "set AmplePropertyIsFeature");
	  hr = pPatr->put_PromoteDefaultAtoms(m_bPromoteDefaultAtomicValues);
	  checkResults(hr, "set PromoteDefaultAtoms");
	  hr = pPatr->put_Failures(m_bShowFailures);
	  checkResults(hr, "set Failures");
	  hr = pPatr->put_DisplayFeatures(m_bDisplayFeatures);
	  checkResults(hr, "set DisplayFeatures");
	  hr = pPatr->put_TopFeatureOnly(!m_bAllFeatures);
	  checkResults(hr, "set TopFeatureOnly");
	  hr = pPatr->put_Gloss(m_bDisplayGloss);
	  checkResults(hr, "set Gloss");
	  hr = pPatr->put_TrimEmptyFeatures(m_bTrimEmptyFeatures);
	  checkResults(hr, "set TrimEmptyFeatures");
	  hr = pPatr->put_Unification(m_bPerformUnification);
	  checkResults(hr, "set Unification");
	  hr = pPatr->put_WriteAmpleParses(m_bWriteAmpleParses);
	  checkResults(hr, "set WriteAmpleParses");
	  hr = pPatr->put_MaxAmbiguity(m_uiMaxAmbiguities);
	  checkResults(hr, "set MaxAmbiguity");
	  hr = pPatr->put_SentenceFinalPunctuation(
				 m_sSentenceFinalPunctuation.AllocSysString());
	  checkResults(hr, "set SentenceFinalPunctuation");
	  hr = pPatr->put_TimeLimit(m_uiTimeLimit);
	  checkResults(hr, "set TimeLimit");
	  hr = pPatr->put_TreeDisplay(m_iTreeDisplayFormat);
	  checkResults(hr, "set TreeDisplay");
	  hr = pPatr->put_FlatFeatureDisplay(m_bFlatFeatureDisplay);
	  checkResults(hr, "set FlatFeatureDisplay");
	  hr = pPatr->LoadGrammarFile(m_sGrammarFileName.AllocSysString());
	  checkResults(hr, "load grammar file");
	  CString s = m_sLOGPath.getQuotedPath();
	  CString sLogFile = s.Mid(1, s.GetLength()-2);
	  hr = pPatr->OpenLog(sLogFile.AllocSysString());
	  checkResults(hr, "set log file");
	  s = m_sOutPath.getQuotedPath();;
	  CString sOutFile = s.Mid(1, s.GetLength()-2);
	  hr = pPatr->DisambiguateAnaFile(m_sInPath.getShortPath().AllocSysString(),
					  sOutFile.AllocSysString());
	  checkResults(hr, "disambiguate ANA file");
	  hr = pPatr->CloseLog();
	  checkResults(hr, "close log file");
#endif // hab245
	  pPatr->Release();
	  pPatr = NULL;
	  CoUninitialize();

	  waitForCompletion(&status, &m_sLOGPath, &m_sOutPath);

	  // register ana output so the user can view it
	  CString sShortDesc, sLongDesc, sTabLabel;
	  CCarlaLanguage *pOutANALang=NULL;
	  sShortDesc = "PC-PATR Disambiguated ANA";
	  sLongDesc = "ANA of the source-language file, after filtering through PC-PATR Syntactic Grammar rules.";
	  sTabLabel = "PATR-Disamb ANA";
	  pOutANALang = status.getInputLang();
	  CResultStreamFile* anaStream =
	new CResultStreamFile(
		  new CResultStreamDescriptor(this,
					  sShortDesc, //short description
					  sLongDesc, // long description
					  sTabLabel // tab label
					  ),
		  m_sOutPath.getFullPath(),
		  pOutANALang);
	  status.registerResultStream(anaStream);

	  registerLog(status, m_sLOGPath, status.getInputLang());
	  status.sANAPath = m_sOutPath;
	}
  catch(CProcessFailure failure)
	{
	  registerLog(status, m_sLOGPath);
	  throw(failure);
	}
  catch(CString sError)
	{
	  registerLog(status, m_sLOGPath);
	  throw(CProcessFailure(this, sError));
	}
}
Ejemplo n.º 18
0
void Database_PostgreSQL::endSave()
{
	checkResults(PQexec(m_conn, "COMMIT;"));
}
Ejemplo n.º 19
0
bool CppSQLite3Table::fieldIsNull(const char* szField)
{
	checkResults();
	return (fieldValue(szField) == 0);
}
Ejemplo n.º 20
0
Archivo: main.cpp Proyecto: CCJY/coliru
void benchmark(int samples = 1)
{
	std::cout << std::string(70, '-') << std::endl
	          << getTypeName<T>()
	          << " conversion (size = " << sizeof(T)*8 << " bits) - ";

	std::vector<std::string> strings = generateRandStrings<T>(numNumbers);

	std::cout << std::string(70, '-') << std::endl;

	////
	std::cout << "  stringstream: ";
	if (checkResults(strings, stringstream_convert<T>))
		time_run<T>(strings, stringstream_convert<T>, samples);
	else
		std::cout << "FAILURE" << std::endl;

	////
	std::cout << "        sscanf: ";
	if (checkResults(strings, sscanf_convert<T>))
		time_run<T>(strings, sscanf_convert<T>, samples);
	else
		std::cout << "FAILURE" << std::endl;

	////
	std::cout << "          stoi: ";
	if (sizeof(T) > sizeof(int))
		std::cout << "SKIPPED" << std::endl;
	else if (checkResults(strings, stoi_convert<T>))
		time_run<T>(strings, stoi_convert<T>, samples);
	else
		std::cout << "FAILURE" << std::endl;

	////
	std::cout << "        strtol: ";
	if (sizeof(T) > sizeof(long))
		std::cout << "SKIPPED" << std::endl;
	else if (checkResults(strings, strtol_convert<T>))
		time_run<T>(strings, strtol_convert<T>, samples);
	else
		std::cout << "FAILURE" << std::endl;

	std::cout << "          stol: ";
	if (sizeof(T) > sizeof(long))
		std::cout << "SKIPPED" << std::endl;
	else if (checkResults(strings, stol_convert<T>))
		time_run<T>(strings, stol_convert<T>, samples);
	else
		std::cout << "FAILURE" << std::endl;

	std::cout << "       strtoll: ";
	if (sizeof(T) > sizeof(long long))
		std::cout << "SKIPPED" << std::endl;
	else if (checkResults(strings, strtoll_convert<T>))
		time_run<T>(strings, strtoll_convert<T>, samples);
	else
		std::cout << "FAILURE" << std::endl;

	std::cout << "         stoll: ";
	if (sizeof(T) > sizeof(long long))
		std::cout << "SKIPPED" << std::endl;
	else if (checkResults(strings, stoll_convert<T>))
		time_run<T>(strings, stoll_convert<T>, samples);
	else
		std::cout << "FAILURE" << std::endl;

	std::cout << "     handcoded: ";
	if (checkResults(strings, handcoded_convert<T>))
		time_run<T>(strings, handcoded_convert<T>, samples);
	else
		std::cout << "FAILURE" << std::endl;


	std::cout << "        hybrid: ";
	if (checkResults(strings, hybrid_convert<T>))
		time_run<T>(strings, hybrid_convert<T>, samples);
	else
		std::cout << "FAILURE" << std::endl;

}
Ejemplo n.º 21
0
int main(int argc, char *argv[])
{
  int i;

#ifdef EPETRA_MPI
  // Initialize MPI
  MPI_Init(&argc,&argv);
  Epetra_MpiComm comm(MPI_COMM_WORLD);
#else
  Epetra_SerialComm comm;
#endif

  // Uncomment to debug in parallel int tmp; if (comm.MyPID()==0) cin >> tmp; comm.Barrier();

  bool verbose = false;

  // Check if we should print results to standard out
  if (argc>1) if (argv[1][0]=='-' && argv[1][1]=='v') verbose = true;

  if (!verbose) comm.SetTracebackMode(0); // This should shut down any error traceback reporting

  if (verbose) cout << comm << endl << flush;

  if (verbose) verbose = (comm.MyPID()==0);

  if (verbose)
    cout << EpetraExt::EpetraExt_Version() << endl << endl;

  int nx = 128;
  int ny = comm.NumProc()*nx; // Scale y grid with number of processors

  // Create funky stencil to make sure the matrix is non-symmetric (transpose non-trivial):

  // (i-1,j-1) (i-1,j  )
  // (i  ,j-1) (i  ,j  ) (i  ,j+1)
  // (i+1,j-1) (i+1,j  )

  int npoints = 7;

  int xoff[] = {-1,  0,  1, -1,  0,  1,  0};
  int yoff[] = {-1, -1, -1,  0,  0,  0,  1};

  Epetra_Map * map;
  Epetra_CrsMatrix * A;
  Epetra_Vector * x, * b, * xexact;
	
  Trilinos_Util_GenerateCrsProblem(nx, ny, npoints, xoff, yoff, comm, map, A, x, b, xexact);

  if (nx<8)
  {
    cout << *A << endl;
    cout << "X exact = " << endl << *xexact << endl;
    cout << "B       = " << endl << *b << endl;
  }

  // Construct transposer 
  Epetra_Time timer(comm);

  double start = timer.ElapsedTime();

  //bool IgnoreNonLocalCols = false;
  bool MakeDataContiguous = true;
  EpetraExt::RowMatrix_Transpose transposer( MakeDataContiguous );

  if (verbose) cout << "\nTime to construct transposer  = " << timer.ElapsedTime() - start << endl;
  
  Epetra_CrsMatrix & transA = dynamic_cast<Epetra_CrsMatrix&>(transposer(*A));

  start = timer.ElapsedTime();
  if (verbose) cout << "\nTime to create transpose matrix  = " << timer.ElapsedTime() - start << endl;
 	
  // Now test output of transposer by performing matvecs
  int ierr = 0;
  ierr += checkResults(A, &transA, xexact, verbose);


  // Now change values in original matrix and test update facility of transposer
  // Add 2 to the diagonal of each row
  double Value = 2.0;
  for (i=0; i< A->NumMyRows(); i++)
  A->SumIntoMyValues(i, 1, &Value, &i);

  start = timer.ElapsedTime();
  transposer.fwd();

  if (verbose) cout << "\nTime to update transpose matrix  = " << timer.ElapsedTime() - start << endl;
 	
  ierr += checkResults(A, &transA, xexact, verbose);

  delete A;
  delete b;
  delete x;
  delete xexact;
  delete map;

  if (verbose) cout << endl << "Checking transposer for VbrMatrix objects" << endl<< endl;

  int nsizes = 4;
  int sizes[] = {4, 6, 5, 3};

  Epetra_VbrMatrix * Avbr;
  Epetra_BlockMap * bmap;

  Trilinos_Util_GenerateVbrProblem(nx, ny, npoints, xoff, yoff, nsizes, sizes,
                                   comm, bmap, Avbr, x, b, xexact);

  if (nx<8)
  {
    cout << *Avbr << endl;
    cout << "X exact = " << endl << *xexact << endl;
    cout << "B       = " << endl << *b << endl;
  }

  start = timer.ElapsedTime();
  EpetraExt::RowMatrix_Transpose transposer1( MakeDataContiguous );

  Epetra_CrsMatrix & transA1 = dynamic_cast<Epetra_CrsMatrix&>(transposer1(*Avbr));
  if (verbose) cout << "\nTime to create transpose matrix  = " << timer.ElapsedTime() - start << endl;
 	
  // Now test output of transposer by performing matvecs
;
  ierr += checkResults(Avbr, &transA1, xexact, verbose);

  // Now change values in original matrix and test update facility of transposer
  // Scale matrix on the left by rowsums

  Epetra_Vector invRowSums(Avbr->RowMap());

  Avbr->InvRowSums(invRowSums);
  Avbr->LeftScale(invRowSums);

  start = timer.ElapsedTime();
  transposer1.fwd();
  if (verbose) cout << "\nTime to update transpose matrix  = " << timer.ElapsedTime() - start << endl;
 	
  ierr += checkResults(Avbr, &transA1, xexact, verbose);

  delete Avbr;
  delete b;
  delete x;
  delete xexact;
  delete bmap;

#ifdef EPETRA_MPI
  MPI_Finalize();
#endif

  return ierr;
}
Ejemplo n.º 22
0
int main(int argc, char* argv[]) {
	printf("\n NODE_BIND:%d, NUMA:%d, CPU_BIND:%d, FIRST_TOUCH:%d\n",NODE_BIND, NUMA, CPU_BIND, FIRST_TOUCH);

        int repetitions, // number of repetition 
			maxThreads, // max number of threads
			it,
                        N; // array size;
        int bitCount = 1;
	int * key; // array of keys
	long * dataIn; // input data
	long * dataSTL; // input stl data
	long * dataRadix; // input radix data

        repetitions = 1;
#pragma omp parallel
	maxThreads = omp_get_num_threads();

        if(argc ==1 ){
            printf("prog input_file number_of_elements bit_count number_of_repetitions\n");
            printf("NO INPUT FILE");
            return 0;
        }
        if(argc == 2){
            printf("prog input_file number_of_elements bit_count number_of_repetitions\n");
            printf("NO ELEMENT COUNT\n");
            return 0;
        }
        if(argc >2 ){
	    N = (int) strtol(argv[2], NULL, 10);
        }
        if(argc >3){
             int tmp;
	    tmp = (int) strtol(argv[3], NULL, 10);
	    if ((tmp > 0) && (tmp<=16 )) // limit bit count
		bitCount = tmp;
        }        
        if(argc >4){
             int tmp;
	    tmp = (int) strtol(argv[4], NULL, 10);
	    if ((tmp > 0) && (tmp<=10000 )) // limit repetitions
		repetitions = tmp;
        }

        int *input;
	size_t N2;
	printf( "Reading data from file.\n" );
        if( readIntArrayFile( argv[1], &input, &N2 ) )
           return 1; 
	printf( "Data reading done.\n" );

        if( (N2<(size_t)N) || (N<=0) )
		N = N2;


       	printf( "\nPARALLEL STL SORT for N=%d, max threads = %d, test repetitions: %d\n", N, maxThreads, repetitions);

	dataIn = new long[N]; 
	dataSTL = new long[N];

#ifdef _WIN32

	dataRadix = new long[N];
	key = new int[N];
#endif
#ifdef linux

	key = new int[N];
#if NUMA==0

	dataRadix = new long[N]; 

#elif NUMA==1
			dataRadix = (long*) numa_alloc_interleaved(N * sizeof(long));
#elif NUMA==2
			dataRadix = (long*)numa_alloc_onnode(sizeof(long)*N,1);
#endif
#endif
	VTimer stlTimes(maxThreads);
	VTimer radixTimes(maxThreads);
#if TIME_COUNT==1
	VTimer partTimes(TIMERS_COUNT);
#endif
#if FLUSH_CACHE==1
#ifdef linux
        CacheFlusher cf;
#endif
#endif

        for(long i=0;i<N;i++)
		dataIn[i]=input[i];
	delete[] input;

// loop from 1 to maxThreads
	for (int t = 1; t <= maxThreads; t++) {
		int i;
#if TIME_COUNT==1
                partTimes.reset();
#endif
#if CALC_REF==1
// parallel STL
		for (it = 0; it < repetitions; it++) {
			setThreadsNo(t, maxThreads);
#pragma omp parallel for private(i)
			for (i = 0; i < N; i++)
				dataSTL[i] = dataIn[i];
#if FLUSH_CACHE==1
#ifdef linux
                        cf.flush();
#endif
#endif
			stlTimes.timerStart(t-1);

#ifdef linux
			__gnu_parallel::sort(dataSTL, dataSTL + N);
#endif
#ifdef _WIN32
			std::sort(dataSTL, dataSTL + N);
#endif
			stlTimes.timerEnd(t-1);
		}

#if FLUSH_CACHE==1
#ifdef linux
                cf.flush();
#endif
#endif
#endif

// radix sort V1
		for (it = 0; it < repetitions; it++) {
			setThreadsNo(t, maxThreads);
#pragma omp parallel for private(i) default(shared)

			for (i = 0; i < N; i++){
				dataRadix[i] = dataIn[i];
				key[i]=i;
			}

#if FLUSH_CACHE==1
#ifdef linux
                        cf.flush();
#endif
#endif
			omp_set_num_threads(t);
			radixTimes.timerStart(t-1);
#if TIME_COUNT==1
                        prsort::pradsort<long,int>(dataRadix,key, N, bitCount,&partTimes);
#else
                        prsort::pradsort<long,int>(dataRadix,key, N,bitCount,NULL);
#endif
			radixTimes.timerEnd(t-1);

		}

       
#if CALC_REF==1
		printf("|STL   SORT(th=%2d)  : %1.3fs  |\t", t,
				stlTimes.getTime(t-1));
#endif
#if TIME_COUNT==1
		for (int i = 0; i < TIMERS_COUNT; i++) {
#if CREATE_OUTPUT==1
			printf("%d %d %d %d %d %d %d %f\n", NUMA, NODE_BIND, CPU_BIND, FIRST_TOUCH,bitCount , t, i ,partTimes.getTime(i));
#else
			printf("part%d :%f ", i, partTimes.getTime(i));
#endif

		}
#endif
#if CREATE_OUTPUT ==1
		        printf("%d %d %d %d %d %d calosc %1.3f", NUMA,NODE_BIND,CPU_BIND,FIRST_TOUCH,bitCount, t ,radixTimes.getTime(t-1));
#else
		printf("|RADIX SORT (th=%2d)  : %1.3fs  |\t", t,
				radixTimes.getTime(t-1));
#endif

// Attention: checking result only from the last function usage 

#if CALC_REF==1
		checkResults(dataSTL, dataRadix, N);
#else
		printf("\n");
#endif

#if CHECK_KEY==1
	if(checkKey(dataIn,dataRadix,key,N))printf("Keys are good\n");

#endif
	}

#ifdef linux
	delete[] key;
#if NUMA>0
	numa_free(dataRadix, sizeof(long) * N);
        
#else

	delete[] dataRadix;
#endif
#endif
#ifdef _WIN32
	delete[] dataRadix;
#endif

	delete[] dataIn;
	delete[] dataSTL;
	
#if TIME_COUNT==1
	
        
        
#endif
	return 0;
}
Ejemplo n.º 23
0
void Database_PostgreSQL::beginSave()
{
	verifyDatabase();
	checkResults(PQexec(m_conn, "BEGIN;"));
}