Beispiel #1
0
static double time_calc(int rds)
{
  if (mpi_integrate(0, 0))
    return -1;

  /* perform force calculation test */
  markTime();
    if (mpi_integrate(rds, -1))
      return -1;
  markTime();
  return diffTime()/rds;
}
Beispiel #2
0
int main(int argc, char *argv[]) {
    if (argc != 3) {
        printf("usage: ./project1 [nrThreads] [iterations]\n");
        return 1;
    }
    
    int num_cores = sysconf(_SC_NPROCESSORS_ONLN);
    printf("Number of cores: %d\n", num_cores);
    double elapsedTime;
    elapsedTime = markTime();

    // The first argument is the number of threads executing simultaneously
    int nrThreads = atoi(argv[1]);
    // number of iterations performed in tfunc for each thread
    int iterations = atoi(argv[2]) / nrThreads;
    pthread_t thread_id[nrThreads];
    int status, *p_status = &status;

    printf("%-25s| %-25s\n", "Number of threads", "Number of iterations");
    printf("%-25d| %-25d\n", nrThreads, iterations);
    int i = 0;
    for (i = 0; i < nrThreads; ++i) {    // generate threads
        // First argument: as each thread is created, its thread ID is saved in the thread_id array
        // Second argument: NULL - each created thread has the default set of attributes
        // Third argument: the function executed in the thread
        // Fourth: the argument passed to the function executed in the thread
        if( pthread_create(&thread_id[i], NULL, tfunc, (void*)iterations) > 0){	    
            printf("pthread_create failure with Thread Nr. %d\n", i);
            return 2;
        } else {
			if(i %2 == 0) assignToCore(0, thread_id[i]);
			else assignToCore(1, thread_id[i]);			
		}
    }
    
    for (i=0; i < nrThreads; ++i) {      // wait for each thread
        // After the creation of the threads, the program waits for the threads to finish
        if ( pthread_join(thread_id[i], (void **) p_status) > 0){
            printf("pthread_join failure with Thread Nr. %d\n", i);
            return 3;
        }        
        // printf("Thread Nr. %d, Thread ID: [%d] returns\n", i, thread_id[i]);
        
    }
    elapsedTime = markTime() - elapsedTime;
    printf("Finished in %.3f seconds. \n", elapsedTime);

    return 0;
}
Beispiel #3
0
void Subtitles::show() {
	Sound &sound = *g_vm->_sound;
	Windows &windows = *g_vm->_windows;

	if (!sound._subtitles || !active() || g_vm->shouldExit()) {
		// Subtitles aren't needed
		reset();
	} else {
		if (timeElapsed()) {
			_lineEnd = (_lineEnd + 1) % _lineSize;
			int count = MAX(_lineEnd - 40, 0);

			// Get the portion of the line to display
			char buffer[1000];
			strncpy(buffer, _lines[_lineNum].c_str() + count, _lineEnd - count);
			buffer[_lineEnd - count] = '\0';

			// Form the display line
			_displayLine = Common::String::format(SUBTITLE_LINE, buffer);
			markTime();
		}

		// Draw the box sprite
		if (!_boxSprites)
			// Not already loaded, so load it
			_boxSprites = new SpriteResource("box.vga");
		_boxSprites->draw(0, 0, Common::Point(36, 189));

		// Write the subtitle line
		windows[0].writeString(_displayLine);

		if (_lineEnd == 0)
			reset();
	}
}
Beispiel #4
0
double time_force_calc(int default_samples)
{
  int rds = timing_samples > 0 ? timing_samples : default_samples;
  int i;

  if (mpi_integrate(0, 0))
    return -1;

  /* perform force calculation test */
  markTime();
  for (i = 0; i < rds; i++) {
    if (mpi_integrate(0, -1))
      return -1;
  }
  markTime();
  return diffTime()/rds;
}
Beispiel #5
0
void Subtitles::setLine(int line) {
	if (_lines.empty())
		loadSubtitles();

	markTime();
	_lineNum = line;
	_lineSize = _lines[_lineNum].size();
	_lineEnd = 1;
	_displayLine.clear();
}
Beispiel #6
0
/**
 * Begin the clock running.
 * Typical usage one-period usage is Start() ... do something ... Stop(), 
 * GetTime(), Reset(). 
 *
 * For timing multiple periods, the typical pattern is:
 * 
 * @code
 *   timer.Start();
 *   //... do something ...
 *   timer.Start();
 *   //... do something again ...
 *   //... repeat
 * @endcode
 *
 * then finally call Stop(), GetAvgTime(), and Reset().
 */
inline void StopwatchBase::Start()
{
  if (running) {
    numStarts++;
    return;
  }
  running = true;
  numStarts++;
  // markTime call should be last thing in function so we avoid timing 
  // our own activity as much as possible.
  markTime();
}
Beispiel #7
0
// constructor
br::com::sbVB::VBLib::VBClock::VBClock() 
{ 
	markTime(); 
}
Beispiel #8
0
/**
 * Reset all the internal clock data.  
 * Safe to call even if the clock is currently running.
 * (i.e. in between a Start() and a Stop() pair).
 */
inline void StopwatchBase::Reset()
{
  if (running) { markTime(); numStarts=1; }
  else numStarts = 0;
  elapsedTime = 0.0f;
}
Beispiel #9
0
bool
DataItem::readData(string &fileName, uint64_t &coprocReq, uint64_t &hostReq)
{
    int64_t                                 t;
    int                                     b;
    int                                     c;
    map<int64_t, DataItem *>::iterator      itr;
    int64_t                                 timeMax;
    unsigned short                          *reqP;
    int                                     cntr = 0;
    size_t                                  pos;
    string                                  fn;

    //
    //  load the data
    //
    pos = fileName.find_last_of("/\\");
    if(pos == string::npos) {
        pos = 0;
    } else {
        pos++;              // skip the /
    }
    hostReq = 0;
    fn = fileName.substr(pos);
    if(fn.compare("__internal1.htmt") == 0) {
        coprocReq = generateItems(1);
    } else if(fn.compare("__internal2.htmt") == 0) {
        coprocReq = generateItems(2);
    } else {
        if(readDataFile(fileName, coprocReq, hostReq) == false) {
            return(false);
        }
    }
    //
    //  Now generate the outstanding request map for the data
    //  NOTE: it is 0 based
    //
    StatusData status("Generating Tables...", 0, CTLR_MAX * BANKS);
    markTime(true, "Table Start");
    timeMax = lastRetire - firstStart + 1;
    for(c=0; c<CTLR_MAX; c++) {                     // controller
        for(b=0; b<BANKS; b++) {                    // bank
            status.setValue(++cntr);
            if((cntr%100)==0 && status.wasCanceled()) {
                status.clear();
                cleanup();                          // remove any data
                return(false);
            }
            unsigned short *sp;
            ctlrBandTimeReq[c][b] = sp = (unsigned short *)calloc(timeMax, sizeof(*reqP));
            map<int64_t, DataItem *>::iterator      itrEnd;
            itrEnd = dataMap[c][b].end();
            
            for(itr = dataMap[c][b].begin(); itr != itrEnd; itr++) {
                int64_t tStart = itr->second->getStartTime();
                int64_t tEnd = itr->second->getRetireTime();
                tStart -= firstStart;
                tEnd -= firstStart;
                for(t=tStart; t<= tEnd; t++) {
                    sp[t]++;
                }
            }
            
#ifdef NEVER
            for(itr = dataMap[c][b].begin(); itr != dataMap[c][b].end(); itr++) {
                for(t=itr->second->getStartTime(); t<= itr->second->getRetireTime(); t++) {
                    ctlrBandTimeReq[c][b][t - firstStart]++;
                }
            }
#endif
        }
    }
    markTime(false, "Table Stop");
    status.clear();
    return(true);
}