Esempio n. 1
0
File: main.cpp Progetto: CCJY/coliru
int main()
{
    const int size = 1 << 20;
    std::vector<int> vec;
    for (int i = 0; i < size; i++)
    {
        if (i == 59)
        {
            vec.push_back(1000000012);
        }
        else
        {
            vec.push_back(i);
        }
    }

    double startTime = getRealTime();
    int maxArray = *std::max_element(vec.begin(), vec.end());
    double stopTime = getRealTime();
    double totalArrayTime = stopTime - startTime;
    
    startTime = getRealTime();
    int maxIter = *std::max_element(vec.begin(), vec.end());
    stopTime = getRealTime();
    double totalIteratorTime = stopTime - startTime;

    std::cout << "MaxIter = " << maxIter << std::endl;
    std::cout << "MaxArray = " << maxArray << std::endl;
    std::cout << "Total CPU time iterator = " << totalIteratorTime << std::endl;
    std::cout << "Total CPU time array = " << totalArrayTime << std::endl;
    std::cout << "iter/array ratio: = " << totalIteratorTime / totalArrayTime << std::endl;
    return 0;
}
Esempio n. 2
0
// Thread for displaying EMG data in real time
void* DATA_fun()
{
   float64* data; // Memory allocated and freed by EMG
   double lastAccess = getRealTime();

   // Wait until emgServer is collecting data
   while (!emgServer->isRunning()){}
   // Now stay in loop until it is done running
   while (emgServer->isRunning() && !quitTest)
   {
       if (getRealTime()-lastAccess > 1)
       {
           // Collect most recent sample
           data = emgServer->getEMGData();

           // Print out current time and EMG from each channel
           fprintf(stdout,"%0.3f: ",getRealTime());
           for (size_t i = 0; i < emgServer->numChannels();i++)
               fprintf(stdout,"%0.4f\t", data[i]);
           fprintf(stdout,"\n");

           // Save current time for next output in 1 second
           lastAccess = getRealTime();
       }
   }

}
Esempio n. 3
0
  void LapackLuDense::solve(double* x, int nrhs, bool transpose) {
    double time_start=0;
    if (CasadiOptions::profiling&& CasadiOptions::profilingBinary) {
      time_start = getRealTime(); // Start timer
      profileWriteEntry(CasadiOptions::profilingLog, this);
    }

    // Scale the right hand side
    if (transpose) {
      rowScaling(x, nrhs);
    } else {
      colScaling(x, nrhs);
    }

    // Solve the system of equations
    int info = 100;
    char trans = transpose ? 'T' : 'N';
    dgetrs_(&trans, &ncol_, &nrhs, getPtr(mat_), &ncol_, getPtr(ipiv_), x, &ncol_, &info);
    if (info != 0) throw CasadiException("LapackLuDense::solve: "
                                        "failed to solve the linear system");

    // Scale the solution
    if (transpose) {
      colScaling(x, nrhs);
    } else {
      rowScaling(x, nrhs);
    }

    if (CasadiOptions::profiling && CasadiOptions::profilingBinary) {
      double time_stop = getRealTime(); // Stop timer
      profileWriteTime(CasadiOptions::profilingLog, this, 1,
                       time_stop-time_start, time_stop-time_start);
      profileWriteExit(CasadiOptions::profilingLog, this, time_stop-time_start);
    }
  }
Esempio n. 4
0
  void LapackLuDense::prepare() {
    double time_start=0;
    if (CasadiOptions::profiling && CasadiOptions::profilingBinary) {
      time_start = getRealTime(); // Start timer
      profileWriteEntry(CasadiOptions::profilingLog, this);
    }
    prepared_ = false;

    // Get the elements of the matrix, dense format
    input(0).get(mat_);

    if (equilibriate_) {
      // Calculate the col and row scaling factors
      double colcnd, rowcnd; // ratio of the smallest to the largest col/row scaling factor
      double amax; // absolute value of the largest matrix element
      int info = -100;
      dgeequ_(&ncol_, &nrow_, getPtr(mat_), &ncol_, getPtr(r_),
              getPtr(c_), &colcnd, &rowcnd, &amax, &info);
      if (info < 0)
          throw CasadiException("LapackQrDense::prepare: "
                                "dgeequ_ failed to calculate the scaling factors");
      if (info>0) {
        stringstream ss;
        ss << "LapackLuDense::prepare: ";
        if (info<=ncol_)  ss << (info-1) << "-th row (zero-based) is exactly zero";
        else             ss << (info-1-ncol_) << "-th col (zero-based) is exactly zero";

        userOut() << "Warning: " << ss.str() << endl;



        if (allow_equilibration_failure_)  userOut() << "Warning: " << ss.str() << endl;
        else                              casadi_error(ss.str());
      }

      // Equilibrate the matrix if scaling was successful
      if (info!=0)
        dlaqge_(&ncol_, &nrow_, getPtr(mat_), &ncol_, getPtr(r_), getPtr(c_),
                &colcnd, &rowcnd, &amax, &equed_);
      else
        equed_ = 'N';
    }

    // Factorize the matrix
    int info = -100;
    dgetrf_(&ncol_, &ncol_, getPtr(mat_), &ncol_, getPtr(ipiv_), &info);
    if (info != 0) throw CasadiException("LapackLuDense::prepare: "
                                         "dgetrf_ failed to factorize the Jacobian");

    // Success if reached this point
    prepared_ = true;

    if (CasadiOptions::profiling && CasadiOptions::profilingBinary) {
      double time_stop = getRealTime(); // Stop timer
      profileWriteTime(CasadiOptions::profilingLog, this, 0, time_stop-time_start,
                       time_stop-time_start);
      profileWriteExit(CasadiOptions::profilingLog, this, time_stop-time_start);
    }
  }
Esempio n. 5
0
int main(const int argc, const char **argv){

	if (argc < 3){

		std::cerr << "Error: too few arguments." << std::endl;
		return 1;

	}

	const int64_t SIZE 		  = std::stoull(argv[1]);
	const int64_t NUM_THREADS = std::stoull(argv[2]);

	if (SIZE < 10 || NUM_THREADS < 1){

		std::cerr << "Error: Invalid aruments " << SIZE << " and " << NUM_THREADS << std::endl;
		return 1;

	}

	dispatch_init();

	std::cout << "Creating matricies..." << std::endl;
	std::cout << "Size: " << SIZE << ", Threads: " << NUM_THREADS << std::endl;

	const double createStart = getRealTime();

	Matrix *mat1 = createMatrix(SIZE);
	Matrix *mat2 = createMatrix(SIZE);
	Matrix *mat3 = createMatrix(SIZE);

	initMatrix(mat1);
	initMatrix(mat2);

	const double createEnd = getRealTime();
	const double createElapsed = createEnd - createStart;

	std::cout << "Matricies created. Took " << createElapsed << " seconds." << std::endl;
	std::cout << "Multiplying..." << std::endl;

	const double multiplyStart = getRealTime();

	multiplyParallel(mat1, mat2, mat3, NUM_THREADS);

	const double multiplyEnd = getRealTime();
	const double multiplyElapsed = multiplyEnd - multiplyStart;
	
	std::cout << "Multiply finished. Took " << multiplyElapsed << " seconds." << std::endl;

	destroyMatrix(mat1);
	destroyMatrix(mat2);
	destroyMatrix(mat3);

	disaptch_release();
	return 0;

}
Esempio n. 6
0
int getNClicks() {
	if( mouseTime == -1 )
		mouseTime = getRealTime();
	int time = getRealTime() - mouseTime;
	if( time < 2000 )
		return 1;
	else if( time < 5000 )
		return 2;
	return 3;
}
Esempio n. 7
0
int main(const int argc, const char **argv){

	if (argc < 2){

		usage(argv[0]);
		exit(EXIT_FAILURE);

	}

	//read the size of the matrix to make
	const int64_t size = std::stoll(argv[1]);

	if (size <= 0){

		std::cerr << "Error: Overflow in matrix size." << std::endl;
		exit(EXIT_FAILURE);

	}

	std::cout << "Creating matricies..." << std::endl;
	std::cout << "Size: " << size << std::endl;

	const double createStart = getRealTime();

	Matrix *mat1 = createMatrix(size);
	Matrix *mat2 = createMatrix(size);
	Matrix *mat3 = createMatrix(size);

	initMatrix(mat1);
	initMatrix(mat2);

	const double createEnd = getRealTime();
	const double createElapsed = createEnd - createStart;

	std::cout << "Matricies created. Took " << createElapsed << " seconds." << std::endl;
	std::cout << "Multiplying serially..." << std::endl;

	const double multiplyStart = getRealTime();

	multiplySerial(mat1, mat2, mat3);

	const double multiplyEnd = getRealTime();
	const double multiplyElapsed = multiplyEnd - multiplyStart;
	
	std::cout << "Multiply finished. Took " << multiplyElapsed << " seconds." << std::endl;

	destroyMatrix(mat1);
	destroyMatrix(mat2);
	destroyMatrix(mat3);

	return 0;

}
Esempio n. 8
0
int main (int argc, char *argv[]) {
    const int arrSize = atoi(argv[1]);

    int *a = (int*) malloc(sizeof(int)*arrSize);
    int *b = (int*) malloc(sizeof(int)*arrSize);
    int i;
    for(i = 0; i < arrSize; i++) {
        a[i] = i%4;
        b[i] = i%4;
    }
    int * volatile res = malloc(arrSize*sizeof(int));

    init();


    /// Test
    double t1,t2;
    int const iter = 10;
    printf("Running test of size %d (%d iterations)\n", arrSize, iter);
    printf("Before: ");
    for (int i=0; i<min(arrSize,10); i++)
    {
        printf("%d ", a[i]);
        printf("%d ", b[i]);
    }
    printf("\n");

    for (int i=-2; i<iter; i++) // Negative i is warmup
    {
        if (i == 0)
            t1 = getRealTime();
        f0(a, arrSize, b, arrSize, &res);
    }
    t2 = getRealTime();
    double nanos = (t2 - t1) * 1.0e9 / iter;

    outputMeasure("dotPIRE.log",nanos, arrSize);

    printf("After:  ");
    for (int i=0; i<min(arrSize,10); i++)
    {
        printf("%d ", res[i]);
    }
    printf("\nhead:%d\n",res[0]);

    /// Teardown
//  teardown();

    free(a);
    free(b);
    free(res);
    return 0;
}
Esempio n. 9
0
int TimeManager::StartStopWatch() {
	stopwatch_rec rec;
	rec.startTime = getRealTime();
	rec.cumulatedTime = 0;
	stopWatches.push_back(rec);
	return stopWatches.size()-1;
}
Esempio n. 10
0
void *mysqlcloud_fn(void * arg)
{
	//与mysqllocal_fn完全相同,只是数据库连接不同
	AbsMsg * absmsg = (AbsMsg*)arg;
	long long realTime;
	int k;
	MYSQL *conn_ptr;  
	conn_ptr = mysql_init(NULL);
	mysql_thread_init();

	//printf("\n远程数据库线程...\n");

	while(1)
	{
		conn_ptr = mysql_real_connect(conn_ptr,"115.28.134.34","root","8bf87c53c9","EcolStation",0,NULL,0);  
		if( !conn_ptr)  {
			printf("Connect to Cloud Mysql failed ! Try to reconnect...\n");  
			sleep(2);
			continue;
		}

		while(1)
		{
			//等待数据接收线程发送的完成信号
			//pthread_mutex_lock(&absmsg->ecollock);
			//printf("Cloud waiting...\n");
			pthread_cond_wait(&dataready2, &absmsg->ecollock2);
			//printf("Cloud 获得信号\n");
			if(msgtype == 0){
				//生态数据
				/*计算准确的时间*/
				realTime = getRealTime(absmsg->ecolmsg -> timeInterval);
				if(insertMySQL(conn_ptr, absmsg->ecolmsg, realTime)){
					printf("Cloud Mysql insert FAIL !\n\n");
					break;
					//pthread_mutex_unlock(&absmsg->ecollock);
					//mysql_close(conn_ptr);  
					//break;	//数据库操作失败,重新连接数据库
				}
			}else if(msgtype == 1){	
				//邻居数据
				if(updateMySQL(conn_ptr, absmsg->NQueue, 2))
				{
					//数据库操作失败,跳出循环重新连接数据库
					printf("Cloud Mysql Update FAIL !\n\n");
					//pthread_mutex_unlock(&absmsg->ecollock);
					//mysql_close(conn_ptr);  
					break;
				}
				//数据库操作成功,继续循环
			}
			//pthread_mutex_unlock(&absmsg->ecollock);
			//printf("Cloud success!!!\n");
		}
	}
	//mysql_close(conn_ptr);  
}
Esempio n. 11
0
void *mysqllocal_fn(void * arg)
{
	AbsMsg * absmsg = (AbsMsg*)arg;
	long long realTime;
	int k;
	MYSQL *conn_ptr;  
	conn_ptr = mysql_init(NULL);
	mysql_thread_init();

	//printf("\n本地数据库线程...\n");

	while(1)
	{
		conn_ptr = mysql_real_connect(conn_ptr,"localhost","root","gaoxiang","EcolStation",0,NULL,0);  

		if( !conn_ptr)  {
			printf("Connect to Local Mysql failed ! Try to reconnect...\n");  
			sleep(2);
			continue;
		}

		while(1)
		{
			//等待数据接收线程发送的完成信号
			//pthread_mutex_lock(&absmsg->ecollock);
			//printf("获得锁...\n");
			pthread_cond_wait(&dataready1, &absmsg->ecollock1);
			//printf("获得信号...\n");
			if(msgtype == 0){
				//生态数据
				/*计算准确的时间*/
				realTime = getRealTime(absmsg->ecolmsg -> timeInterval);
				printf("Saving to Data Base ====>>\n");
				/*存入数据库*/
				if( !insertMySQL(conn_ptr, absmsg->ecolmsg, realTime)){
					printf("Success !\n\n");
					//操作成功,继续等待数据接收完成
				}
				else{
					printf(" Local Insert FAIL !\n\n");
					//pthread_mutex_unlock(&absmsg->ecollock);
					//mysql_close(conn_ptr);  
					//break;	//数据库操作失败,重新连接数据库
				}
			}else if(msgtype == 1){	
				//邻居数据
				if(updateMySQL(conn_ptr, absmsg->NQueue, 1))
				{
					printf(" Local Update FAIL !\n\n");
				}
				//操作成功,继续循环
			}
			//pthread_mutex_unlock(&absmsg->ecollock);
		}
	}
	//mysql_close(conn_ptr);  
}
Esempio n. 12
0
File: main.c Progetto: atiselsts/osw
void appMain(void)
{
    uint16_t i;

    // ------------------------- serial number
    DPRINTF("Mote %#04x starting...\n", localAddress);

    // ------------------------- external flash
#if WRITE_TO_FLASH
    prepareExtFlash();
#endif

    // ------------------------- light sensors
    if (localAddress != 0x0796) {
        PRINT("init isl\n");
        islInit();
        islOn();
    } else {
        PRINT("init ads\n");
        adsInit();
        adsSelectInput(0);
    }

    // ------------------------- main loop
    mdelay(3000);
    DPRINTF("starting main loop...\n");
    for (i = 0; i < 6; ++i) {
        redLedToggle();
        mdelay(100);
    }
    ledOff();

    uint32_t nextDataReadTime = 0;
    uint32_t nextBlinkTime = 0;
    for (;;) {
        uint32_t now = getRealTime();
        if (timeAfter32(now, nextDataReadTime)) {
            if (getJiffies() < 300 * 1000ul ) {
                nextDataReadTime = now + DATA_INTERVAL_SMALL;
            } else {
                nextDataReadTime = now + DATA_INTERVAL;
            }
            DataPacket_t packet;
            readSensors(&packet);
#if PRINT_PACKET
            printPacket(&packet);
#endif
        }
        if (timeAfter32(now, nextBlinkTime)) {
            nextBlinkTime = now + BLINK_INTERVAL;
            ledOn();
            msleep(100);
            ledOff();
        }
        msleep(1000);
    }
}
Esempio n. 13
0
void TimeManager::PopAndDisplayTime(string textFormat) {
	double start = times[times.size()-1];
	double finish = getRealTime();
	double timeTaken = (finish - start);
	printf(textFormat.c_str(), timeTaken);
#ifdef _WIN32
	flushall();
#endif

	times.pop_back();
}
Esempio n. 14
0
void StopRule::initialize(Params &params) {
	stop_condition = params.stop_condition;
	confidence_value = params.stop_confidence;
	min_iteration = params.min_iterations;
	max_iteration = params.max_iterations;
	unsuccess_iteration = params.unsuccess_iteration;
	min_correlation = params.min_correlation;
	step_iteration = params.step_iterations;
	start_real_time = getRealTime();
	max_run_time = params.maxtime * 60; // maxtime is in minutes
}
void processEvents() {
    Event* event = NULL;
    Time processTime;
    Time platformTime;
    getRealTime(&platformTime);
    set_imask(15);
    event = peekEvent(NULL);
    while (event && higherPriority(event)) {
        safeToProcess(event, &processTime);
        if (compareTime(platformTime, processTime) >= 0) {
            queuePriority(event);
            removeAndPropagateSameTagEvents(event);
            setCurrentModelTag(event);
            set_imask(0);
            fireActor(event);
            getRealTime(&platformTime);
            set_imask(15);
            freeEvent(event);
            stackedDeadlineIndex--;
            event = NULL;
        }
        else {
            if (compareTime(processTime, lastTimerInterruptTime) == LESS) {
                lastTimerInterruptTime.secs = processTime.secs;
                lastTimerInterruptTime.nsecs = processTime.nsecs;
                setTimedInterrupt(&processTime);
            }
        }
        event = peekEvent(event);
    }
    /*
    if (stackedModelTagIndex >= 0) {
        currentMicrostep = executingModelTag[stackedModelTagIndex].microstep;
        currentModelTime = executingModelTag[stackedModelTagIndex].timestamp;
        stackedModelTagIndex--;
    } else {
        DBG(("cannot restore model tag\r\n"));
    }
    */
    set_imask(0);
}
Esempio n. 16
0
int CTimer::getTime()
{
  int result;
  if (running)
  {
    result = getRealTime() - startTime;
  }
  else
  {
    result = pauseTime - startTime;
  }
  return result;
}
Esempio n. 17
0
/*! @brief Constructor for abstract optimiser
 	@param name the name of the optimiser. The name is used in debug logs, and is used for load/save filenames by default
 	@param parameters the initial seed for the optimisation
 */
PSOOptimiser::PSOOptimiser(std::string name, vector<Parameter> parameters) : Optimiser(name, parameters)
{
    //doesn't do anything
    m_inertia = 0.60;       // tune this: this must be less than 1, and can be used to control how long it takes for the algorithm to converge (0.7 converges after about 2000)
    //m_inertia = 0.40;
    //m_inertia = 0.20;

    m_reset_limit = 10;
    m_reset_fraction = 0.05;
    //m_reset_fraction = 0.10;

    //m_num_particles = 30;
    m_num_particles = 60;

    m_num_dimensions = parameters.size();

    srand(static_cast<unsigned int> (1e6*getRealTime()*getRealTime()*getRealTime()));

    load();
    if (m_swarm_position.empty())
    	initSwarm();
    save();
}
Esempio n. 18
0
  void CsparseInterface::solve(double* x, int nrhs, bool transpose) {
    double time_start=0;
    if (CasadiOptions::profiling&& CasadiOptions::profilingBinary) {
      time_start = getRealTime(); // Start timer
      profileWriteEntry(CasadiOptions::profilingLog, this);
    }


    casadi_assert(prepared_);
    casadi_assert(N_!=0);

    double *t = &temp_.front();

    for (int k=0; k<nrhs; ++k) {
      if (transpose) {
        cs_pvec(S_->q, x, t, A_.n) ;       // t = P2*b
        casadi_assert(N_->U!=0);
        cs_utsolve(N_->U, t) ;              // t = U'\t
        cs_ltsolve(N_->L, t) ;              // t = L'\t
        cs_pvec(N_->pinv, t, x, A_.n) ;    // x = P1*t
      } else {
        cs_ipvec(N_->pinv, x, t, A_.n) ;   // t = P1\b
        cs_lsolve(N_->L, t) ;               // t = L\t
        cs_usolve(N_->U, t) ;               // t = U\t
        cs_ipvec(S_->q, t, x, A_.n) ;      // x = P2\t
      }
      x += ncol();
    }

    if (CasadiOptions::profiling && CasadiOptions::profilingBinary) {
      double time_stop = getRealTime(); // Stop timer
      profileWriteTime(CasadiOptions::profilingLog, this, 1,
                       time_stop-time_start,
                       time_stop-time_start);
      profileWriteExit(CasadiOptions::profilingLog, this, time_stop-time_start);
    }
  }
long calculateInvalidationDelay(GifInfo *info, long renderStartTime, uint_fast32_t frameDuration) {
	if (frameDuration) {
		long invalidationDelay = frameDuration;
		if (info->speedFactor != 1.0) {
			invalidationDelay /= info->speedFactor;
		}
		const long renderingTime = getRealTime() - renderStartTime;
		if (renderingTime >= invalidationDelay)
			invalidationDelay = 0;
		else
			invalidationDelay -= renderingTime;
		info->nextStartTime = renderStartTime + invalidationDelay;
		return invalidationDelay;
	}
	return -1;
}
Esempio n. 20
0
__unused JNIEXPORT jlong JNICALL
Java_pl_droidsonroids_gif_GifInfoHandle_renderFrame(JNIEnv *env, jclass __unused handleClass,
                                                    jlong gifInfo, jobject jbitmap) {
    GifInfo *info = (GifInfo *) (intptr_t) gifInfo;
    if (info == NULL)
        return -1;

    time_t renderStartTime = getRealTime();
    void *pixels;
    if (lockPixels(env, jbitmap, info, &pixels) != 0) {
        return 0;
    }
    DDGifSlurp(info, true);
    const uint_fast16_t frameDuration = getBitmap((argb *) pixels, info);
    unlockPixels(env, jbitmap);
    return calculateInvalidationDelay(info, renderStartTime, frameDuration);
}
Esempio n. 21
0
void updateTime(int time) {
	// prevent instability on slow machines
	const int max_interval_c = 200;
	if( time > max_interval_c )
		time = max_interval_c;

	real_loop_time = time;
	real_time += time;

	// Ideally we'd have always had time_rate being an integer, and have all usages of loop_time cope with that, but this would now be a significant change.
	// So we add this fix so that we don't have inaccuracy due to rounding. To test this code, disable wait() in Application::runMainLoop(), which means
	// we'll test this function with very small values of time.
	loop_time = (int)(time * time_ratio_c * time_rate + accumulated_time);
	accumulated_time = (time * time_ratio_c * time_rate + accumulated_time) - loop_time;
	//LOG("time %d loop time %d accumulated %f\n", time, loop_time, accumulated_time);

	game_time += loop_time;
	frame_counter = (getRealTime() * time_rate) / ticks_per_frame_c;
}
Esempio n. 22
0
bool StopRule::meetStopCondition(int cur_iteration, double cur_correlation) {
    if (should_stop)
        return true;
	switch (stop_condition) {
		case SC_FIXED_ITERATION:
			return cur_iteration >= min_iteration;
		case SC_WEIBULL:
			if (predicted_iteration == 0)
				return cur_iteration > min_iteration;
			else
				return cur_iteration > predicted_iteration;
		case SC_UNSUCCESS_ITERATION:
			return cur_iteration > getLastImprovedIteration() + unsuccess_iteration;
		case SC_BOOTSTRAP_CORRELATION:
			return ((cur_correlation >= min_correlation) && (cur_iteration > getLastImprovedIteration() + unsuccess_iteration))
				   || cur_iteration > max_iteration;
		case SC_REAL_TIME:
			return (getRealTime() - start_real_time >= max_run_time);
	}
	return false;
}
Esempio n. 23
0
double StopRule::getRemainingTime(int cur_iteration) {
	double realtime_secs = getRealTime() - start_real_time;
	int niterations;
	switch (stop_condition) {
	case SC_REAL_TIME:
		return max_run_time - realtime_secs;
	case SC_FIXED_ITERATION:
		niterations = min_iteration;
		break;
	case SC_WEIBULL:
		niterations = (predicted_iteration == 0) ? min_iteration : predicted_iteration;
		break;
	case SC_UNSUCCESS_ITERATION:
		niterations = getLastImprovedIteration() + unsuccess_iteration;
		break;
	case SC_BOOTSTRAP_CORRELATION:
		niterations = max(((cur_iteration+step_iteration-1)/step_iteration)*step_iteration, getLastImprovedIteration() + unsuccess_iteration);
//		if (cur_correlation >= min_correlation)
//			niterations = getLastImprovedIteration() + unsuccess_iteration;
		break;
	}
	return (niterations - cur_iteration) * realtime_secs / (cur_iteration - 1);
}
Esempio n. 24
0
/**
 * @retval time Time in milliseconds
 */
double stopTimer( MTime* mtime )
{
  double time = -1.0;
  float milliseconds = 0;
  switch(mtime->type)
  {
    case CPU_CLOCK_TIME:
      time = (mtime->time=1000.0*(getCPUTime( ) - mtime->start));
      break;
    case CPU_WALL_TIME:
      time = (mtime->time=1000.0*(getRealTime() - mtime->start));
      break;
    case GPU_TIME:
      CHECK_ERROR(cudaEventRecord(mtime->gpustop));
      CHECK_ERROR(cudaEventSynchronize(mtime->gpustop));
      CHECK_ERROR(cudaEventElapsedTime(&milliseconds, mtime->gpustart, mtime->gpustop));
      time = static_cast<double>(milliseconds);
      break;
    default:
      throw std::invalid_argument("Unhandled TIME TYPE.");
  }
  return time;
}
Esempio n. 25
0
double Timer::getRealTime(std::string name) const {
    return getRealTime(name);
}
Esempio n. 26
0
int CTimer::start()
{
  startTime += (getRealTime() - pauseTime);
  running = true;
  return getTime();
}
Esempio n. 27
0
int CTimer::pause()
{
  running = false;
  return pauseTime = getRealTime();
}
Esempio n. 28
0
void CTimer::reset(int timeout)
{
  timeoutInterval = timeout;
  startTime = getRealTime();
  pauseTime = startTime;
}
Esempio n. 29
0
 double takeRealTime() { takeTime(); return getRealTime(); }
Esempio n. 30
0
void run_test_a_y(perf_arg_t * para, char* funcname[], a_y_func_t test_func[], a_y_func_t ref_func[],
		   double * flops_per_elem)
{


  VML_INT start=para->start;
  VML_INT end=para->end;
  VML_INT step=para->step;

  double mflops=0.0;
  double time=0.0, start_time, end_time;

  int iscomplex = (para->fp_type & 0x2) >> 1;
  int isdouble = (para->fp_type & 0x1);
  int result=0;
  char * result_str;
  int failed_count=0;

  VML_INT i;

  VML_TEST_LOG("\n");
  VML_TEST_LOG("Func\tN\tTime(s)\t\tResult\n");

  init_rand(end, para->a, iscomplex, isdouble);

  memcpy(para->ref_a, para->a, end * para->element_size * para->compose_size);

  for(i=start; i<=end; i+=step) {

    mflops=flops_per_elem[para->fp_type] * i;

    //need to clean cache
    flush_cache(para->flushcache);

    start_time=getRealTime();
    test_func[para->fp_type](i, para->a, para->y);
    end_time=getRealTime();
    time=end_time-start_time;

    mflops=mflops/(double)(1000000)/time;

    ref_func[para->fp_type](i, para->ref_a, para->ref_y);

    //check
    result=check_vector(i, para->a, para->ref_y, para->y, para->eps, iscomplex, isdouble);

    if(result==0){
      result_str=STR_PASS;
    }else if(result==1){
      result_str=STR_WARN;
    }else{
      result_str=STR_ERR;
      failed_count++;
    }

    VML_TEST_LOG("%s\t%d\t%e\t%s\n", funcname[para->fp_type], i, time, result_str);

  }

  if(failed_count>0) CTEST_ERR("Result failed!\n");
}