本文整理汇总了C++中MyTimer类的典型用法代码示例。如果您正苦于以下问题:C++ MyTimer类的具体用法?C++ MyTimer怎么用?C++ MyTimer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MyTimer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: annotation
void annotation(Float_t a=10, Float_t d=5, Float_t x=0, Float_t y=0, Float_t z=0)
{
TEveManager::Create();
// add a box in scene
TEveBox* b = new TEveBox("Box", "Test Title");
b->SetMainColor(kCyan);
b->SetMainTransparency(0);
b->SetVertex(0, x - a, y - a, z - a);
b->SetVertex(1, x - a, y + a, z - a);
b->SetVertex(2, x + a, y + a, z - a);
b->SetVertex(3, x + a, y - a, z - a);
b->SetVertex(4, x - a, y - a, z + a);
b->SetVertex(5, x - a, y + a, z + a);
b->SetVertex(6, x + a, y + a, z + a);
b->SetVertex(7, x + a, y - a, z + a);
gEve->AddElement(b);
gEve->Redraw3D(kTRUE);
// add overlay text
TGLViewer* v = gEve->GetDefaultGLViewer();
TDatime time;
TGLAnnotation* ann = new TGLAnnotation(v, time.AsString(), 0.1, 0.9);
ann->SetTextSize(0.1);// % of window diagonal
// set timer to update text every second
MyTimer* timer = new MyTimer(ann);
timer->SetTime(1000);
timer->Reset();
timer->TurnOn();
}
示例2: main
int main(int argc, char** argv) {
int n = argc > 1 ? atoi(argv[1]) : 0;
typedef Board T;
//typedef BoardPlus T;
MyTimer timer;
switch (n) {
case 1:
timer.start("construct part");
ContainerBenchmark<ContainerWrapper<ptr_vector<T>>>()(timer);
timer.stop();
break;
case 2:
timer.start("construct part");
ContainerBenchmark<ContainerWrapper<boost::ptr_vector<T>>>()(timer);
timer.stop();
break;
case 3:
timer.start("construct part");
ContainerBenchmark<ContainerWrapper<std::vector<std::shared_ptr<T>>>>()(timer);
timer.stop();
break;
case 4:
timer.start("construct part");
ContainerBenchmark<ContainerWrapper<std::vector<T>>>()(timer);
timer.stop();
break;
}
timer.showResults();
}
示例3: main
int main(int argc, char** argv) {
//const int loop_size = 1000000;
const int loop_size = 100000;
//const int thread_size = std::thread::hardware_concurrency();
const int thread_size = 2;
std::cout << "thread_size = " << thread_size << std::endl;
MyTimer timer;
benchmark<lock_based_queue>("lock_based_queue", timer, thread_size, loop_size);
benchmark<lock_based_stack>("lock_based_stack", timer, thread_size, loop_size);
benchmark<boost_lock_free_queue>("boost_lock_free_queue", timer, thread_size, loop_size);
benchmark<boost_lock_free_stack>("boost_lock_free_stack", timer, thread_size, loop_size);
/*
WorkerThreadGroup<lock_based_queue<std::shared_ptr<BenchMarkTask> > > bm_worker_lbspg(thread_size);
timer.start("lock_based_queue<std::shared_ptr<BenchMarkTask> > group");
for(int i=0; i<loop_size; ++i) {
bm_worker_lbspg.submit(std::make_shared<BenchMarkTask>());
}
bm_worker_lbspg.join();
timer.stop();
*/
/*
WorkerThread<lock_free_queue, BenchMarkJobPolicy> bm_worker_lf;
timer.start("lock_free_queue<BenchMarkTask>");
for(int i=0; i<loop_size; ++i) {
bm_worker_lf.post(BenchMarkJob());
}
bm_worker_lf.join();
timer.stop();
std::cout << "total_counter: " << BenchMarkResource::total_counter << std::endl;
*/
/*
WorkerThreadGroup<lock_free_queue, BenchMarkJobPolicy> bm_worker_lfg(thread_size);
timer.start("lock_free_queue<BenchMarkTask>");
for(int i=0; i<loop_size; ++i) {
bm_worker_lfg.post(BenchMarkJob());
}
bm_worker_lfg.join();
timer.stop();
std::cout << "total_counter: " << BenchMarkResource::total_counter << std::endl;
*/
AsioThreadPool<BenchmarkInitPolicy, BenchmarkEndPolicy> thread_pool(thread_size);
timer.start("AsioThreadPool");
for(int i=0; i<loop_size; ++i) {
thread_pool.post(BenchmarkTask());
}
thread_pool.join();
timer.stop();
std::cout << "total_counter: " << total_counter << std::endl;
//std::cout << "result.value(): " << result.value() << std::endl;
timer.showResults();
}
示例4: main
int main(int argc, char **argv)
{
MyTimer<microsec_clock> t;
for(int i = 0; i < 100; ++i)
{
cout << "hello" << endl;
}
t.Elapsed();
return 0;
}
示例5: MyTimer
void GamePlay::Loop(sf::RenderWindow* target,TextureManager* textureManager) {
sf::Event MyEvent;
MyTimer fps = MyTimer(1000/resource::consts::FPS);
int frame = 0;
fps.StartTimer();
int key_down = 0;
while(_running) {
if(frame % resource::consts::FPS == 0) {
while(target->GetEvent(MyEvent)) {
_player->UpdateKey(MyEvent,_offSet,_map);
switch(MyEvent.Type) {
case sf::Event::KeyPressed:
key_down = 1;
switch(MyEvent.Key.Code) {
case sf::Key::Escape:
_running = false;
break;
}
break;
case sf::Event::KeyReleased:
key_down = false;
break;
}
}
if(!key_down) {
_player->UpdateVelocity(_map);
}
target->Clear();
_player->UpdatePosition();
_player->CollosionLogic(_map);
Render(target,textureManager);
}
target->Display();
frame++;
if( fps.GetTicks() < 1000 / resource::consts::FPS )
{
//Sleep the remaining frame time
// SDL_Delay( ( 1000 / resource::consts::FPS ) - fps.GetTicks() );
}
}
}
示例6: glDisable
void MyControlBarWindow::draw()
{
// the draw method must be private
_controlbar_viewer.set(CONTROLBAR_WIDTH,CONTROLBAR_HEIGHT,0);
_controlbar_viewer.setup2D();
_controlbar_viewer.clearWindow(true);
glDisable(GL_LIGHTING);
int x = 10;
int y = CONTROLBAR_HEIGHT-20;
_controlbar_viewer.drawBox(0,0,CONTROLBAR_WIDTH,CONTROLBAR_HEIGHT,2,RED);
_controlbar_viewer.displayMsg(x,y,"Control Bar",RED,0);
y -= 20;
// print the time
MyTimer timer;
_controlbar_viewer.displayMsg(x,y,(char*)timer.timestring().c_str(),RED,0);
y -= 20;
// print info
// print performance time
_controlbar_viewer.displayMsg(x,y,RED,0,"Frame ID: %d",_main_w_ptr->frameId);
y -= 20;
// print synthetic mode
_controlbar_viewer.displayMsg(x,y,RED,0,"# correspondences: %d",_main_w_ptr->_n_correspondences);
y -= 20;
/*if ( !_main_w_ptr->correspondence_distribution.empty() ) {
// print the distribution
_controlbar_viewer.displayMsg(x, y, BLUE, 0, "CONNECTED: %d", _main_w_ptr->correspondence_distribution[0] );
y -= 20;
_controlbar_viewer.displayMsg(x, y, BLUE, 0, "EXPECTED: %d", _main_w_ptr->correspondence_distribution[1] );
y -= 20;
_controlbar_viewer.displayMsg(x, y, BLUE, 0, "BLACKLISTED: %d", _main_w_ptr->correspondence_distribution[2] );
y -= 20;
}
*/
// print VP scores
_controlbar_viewer.displayMsg(x,y,RED,0,"VP Score: %.4f", scoreSetsOfVanishingPoints(_main_w_ptr->_LUT._vps, _main_w_ptr->_vpc, toRadians(10.0)));
};
示例7: benchmark
void benchmark(std::string benchmark_name, MyTimer& timer, const int thread_size, const int loop_size) {
WorkerThread<Container, BenchmarkJobPolicy> worker_solo;
timer.start(benchmark_name);
for(int i=0; i<loop_size; ++i) {
worker_solo.post(typename BenchmarkJobPolicy::job_type());
}
worker_solo.join();
timer.stop();
std::cout << "total_counter: " << BenchmarkResource::total_counter << std::endl;
WorkerThreadGroup<Container, BenchmarkJobPolicy> worker(thread_size);
timer.start(benchmark_name + " group");
for(int i=0; i<loop_size; ++i) {
//if (i < 100) usleep(10000);
worker.post(typename BenchmarkJobPolicy::job_type());
}
worker.join();
timer.stop();
std::cout << "total_counter: " << BenchmarkResource::total_counter << std::endl;
WorkerThreadGroup<lock_based_queue, BenchmarkJobPointerPolicy> worker_p(thread_size);
timer.start(benchmark_name + " pointer");
for(int i=0; i<loop_size; ++i) {
worker_p.post(new BenchmarkJob);
}
worker_p.join();
timer.stop();
std::cout << "total_counter: " << BenchmarkResource::total_counter << std::endl;
}
示例8: minrand
// 模拟交互过程的函数
unsigned _int64 TestHL::ProtocolFun(const int& tag){
// 获取被选标签的信息
string sql;
sql = "select [Id], [Key] from Tags_HL where Num=";
sql.append(itostr(tag));
adoConn.GetRecordSet(sql.c_str());
if (adoConn.m_pRecordset->GetState() == adStateClosed || adoConn.m_pRecordset->GetRecordCount() == 0)
{
cout << endl << "Tag[" << tag << "] isn't in DataBase." << endl;
return 0;
}
// 生成查询信息
Request_Info req;
req.id= adoConn.m_pRecordset->GetCollect("Id").uintVal;
req.key = adoConn.m_pRecordset->GetCollect("Key").uintVal;
adoConn.CloseRecordset();
// 计时器
MyTimer timer;
// 初始化随机数生成器
minstd_rand0 minrand(timer.GetBegin());
timer.Start();
// 调用模拟标签的函数
Response_Info res = TagFun(req);
// 调用阅读器的函数
Result_Info result = ReaderFun(res);
// 计时器终止
timer.Stop();
return timer.GetTime();
}
示例9: testare_convolutie
void testare_convolutie(const char *fisier_semnal, const char *fisier_filtru)
{
MyTimer timer;
int w_baza = (int)pow(2, 17);
baza = new ZZ(w_baza);
int lambda = 112;
cout << "Securitate = " << lambda << " biti" << endl;
cout << "Baza = " << w_baza << endl;
vector<int> semnal;
vector<int> filtru;
vector<int> convolutie;
citeste_semnal(fisier_semnal, semnal);
citeste_semnal(fisier_filtru, filtru);
/*srand(time(NULL));
for (int i = 0; i < 10; i++)
{
semnal[i] = rand() % 256 - 128;
filtru[i] = rand() % 256 - 128;
}
cout << "Semnal = [ ";
for (int i = 0; i < semnal.size(); i++)
{
cout << semnal[i] << " ";
}
cout << " ]" << endl << "Filtru = [ ";
for (int i = 0; i < filtru.size(); i++)
{
cout << filtru[i] << " ";
}
cout << " ] " << endl;*/
vector<Mat_ZZ> semnal_criptat;
vector<Mat_ZZ> filtru_criptat;
vector<Mat_ZZ> conv_criptata;
HE_Signal he_signal(lambda, w_baza);
cout << "creare he_signal - terminata.\n";
cout << "criptare semnale ...\n";
timer.start_timer();
he_signal.cripteaza_semnal(semnal, semnal_criptat);
cout << "Timp criptare semnal : " << timer.stop_timer << endl;
timer.start_timer();
he_signal.cripteaza_semnal(filtru, filtru_criptat);
cout << "Timp criptare filtru : " << timer.stop_timer() << endl;
cout << "criptare semnale - terminat.\n";
/*vector<int> dec_s1;
vector<int> dec_s2;
he_signal.decripteaza_semnal(dec_s1, semnal_criptat);
he_signal.decripteaza_semnal(dec_s2, filtru_criptat);
scrie_semnal("dec1.dat", dec_s1);
scrie_semnal("dec2.dat", dec_s2);
cout << "scriere semnale decriptate -terminat .\n";*/
timer.start_timer();
cout << "incepe convolutia semnalelor criptate\n";
he_signal.convolutie_semnale(semnal_criptat, filtru_criptat, conv_criptata);
cout << "timp convolutie criptata = " << timer.stop_timer() << endl;
timer.start_timer();
convolutie_semnale(semnal, filtru, convolutie);
cout << "timp convolutie in clar = " << timer.stop_timer() << endl;
vector<int> conv_dec;
he_signal.decripteaza_semnal(conv_dec, conv_criptata);
assert(convolutie.size() == conv_dec.size());
for (int i = 0; i < convolutie.size(); i++)
{
if (convolutie[i] != conv_dec[i])
{
cout << "Semnale diferite\n";
break;
}
}
}
示例10: main
int main(int argc, char *argv[]) {
if (argc != 4) {
printf("Insertion Sort C++\n\n"\
"uso : %s metodo insertion_sort input_file output_file\n"\
"ejm. : %s is input/n1m.txt output/o-n1m.txt\n",
argv[0], argv[0]);
exit(-1);
}
//Número de palabras
int num_palabras;
// Object containing information to control a stream
FILE *infile_ptr = NULL;
FILE *outfile_ptr = NULL;
//Open file for input operations. The file must exist.
infile_ptr = fopen(argv[2], "r+");
outfile_ptr = fopen(argv[3], "w+");
// Timer
MyTimer mt;
int tiempo_total = 0;
printf("Leer archivo... ");
mt.Start();
// read count
char count[MAX_ANCHO_LINEA];
// Get - Leer numero de lineas ubicadas en la cabecera del archivo
// esto es para determinar cuanto de memoria debemos separar
// el valor es solo aproximado, para una mejor gestion
if (fgets(count, MAX_ANCHO_LINEA, infile_ptr) != NULL) {
num_palabras = atoi(count);
}
// Array de lineas
LINE *w_arr;
w_arr = (LINE *)calloc(num_palabras, sizeof(LINE));
NODE *n_arr, *n_head, *n_cur;
n_arr = (NODE *)calloc(num_palabras, sizeof(NODE));
n_head = n_arr;
// read words
int linea;
int num_lineas = 0;
for (linea = 0; !feof(infile_ptr); linea++) {
// using fgets() is faster, but there is '\n' at the end of the string.
fgets(w_arr[linea].data, MAX_ANCHO_LINEA, infile_ptr);
n_arr[linea].vp = w_arr[linea].data;
//printf("n_arr[%i]=%s\n", linea, n_arr[linea].vp);
n_arr[linea].next = &n_arr[linea + 1];
++num_lineas;
}
n_arr[linea - 1].next = NULL;
fclose(infile_ptr);
mt.Stop();
printf("%d ms\n", (int)mt.d_costTime);
tiempo_total += (int)mt.d_costTime;
// sorting
printf("Ordenando... ");
mt.Start();
// obtener Método de Ordenamiento de los parámetros
if ( strcmp(argv[1], "insertion_sort") == 0) {
insertion_sort(n_arr, num_lineas - 1 );
} else {
printf("Metodo no Implementado... ");
return 0;//exit
}
mt.Stop();
printf("%d ms\n", (int)mt.d_costTime);
tiempo_total += (int)mt.d_costTime;
// write to file
printf("Escribir archivo... ");
mt.Start();
fputs(count, outfile_ptr);
n_cur = n_head;
while (1) {
fputs(n_cur->vp, outfile_ptr);
if (n_cur->next == NULL) break;
n_cur = n_cur->next;
}
fclose(outfile_ptr);
mt.Stop();
printf("%d ms\n", (int)mt.d_costTime);
tiempo_total += (int)mt.d_costTime;
printf("Tiempo total en: %d ms\n", tiempo_total);
//.........这里部分代码省略.........
示例11: readData
TagAlignments* readData(const ArgumentParser &args) {//{{{
long i,j,num,tid;
double prb;
long Ntotal=0,Nmap=0,probM=0;
string readId,strand,blank;
ifstream inFile;
MyTimer timer;
TagAlignments *alignments = new TagAlignments(false);
// Read alignment probabilities {{{
inFile.open(args.args()[0].c_str());
FileHeader fh(&inFile);
ns_fileHeader::AlignmentFileType format;
if((!fh.probHeader(&Nmap,&Ntotal,&probM,&format)) || (Nmap ==0)){//{{{
error("Prob file header read failed.\n");
return NULL;
}//}}}
// Use number of transcripts from prob file if it is higher.
if(probM>M)M = probM;
message("N mapped: %ld\n",Nmap);
messageF("N total: %ld\n",Ntotal);
if(args.verb())message("Reading alignments.\n");
if(Ntotal>Nmap)Nunmap=Ntotal-Nmap;
else Nunmap=1; //no valid count file assume only one not aligned properly
alignments->init(Nmap,0,M);
long mod=10000;
long bad = 0;
timer.start();
for(i = 0; i < Nmap; i++) {
inFile>>readId>>num;
if(format==ns_fileHeader::OLD_FORMAT)inFile>>blank;
if(!inFile.good())break;
// message("%s %ld\n",(readId).c_str(),num);
for(j = 0; j < num; j++) {
if(format == ns_fileHeader::OLD_FORMAT)inFile>>tid>>strand>>prb;
else inFile>>tid>>prb;
if(inFile.fail()){
inFile.clear();
// ignore other read's alignments
j=num;
// this read goes to noise assigning
tid=0;
// 10 means either 10 or exp(10), but should be still be large enough
prb=10;
bad++;
}
switch(format){
case ns_fileHeader::OLD_FORMAT:
if(tid!=0) prb /= trInfo.L(tid-1);
case ns_fileHeader::NEW_FORMAT:
alignments->pushAlignment(tid, prb);
break;
case ns_fileHeader::LOG_FORMAT:
alignments->pushAlignmentL(tid, prb);
}
}
// ignore rest of line
inFile.ignore(10000000,'\n');
alignments->pushRead();
R_INTERUPT;
if(args.verb() && (i % mod == 0) && (i>0)){
message(" %ld ",i);
timer.split();
mod*=10;
}
}
示例12: DarkGDK
// the main entry point for the application is this function
void DarkGDK ( void ){
// Seed the random number generator
srand(time(NULL));
// Configure the engine to run as fast as possible (no frame rate cap)
dbSyncOn();
dbSyncRate(0);
// If fullscreen, configure to a, currently, hard coded setting
if (FULLSCREEN) {
dbSetWindowOff();
dbMaximizeWindow();
dbSetDisplayModeAntialias(1680, 1050, 32, 1, 0, 0);
dbSetCameraAspect(0, 1680.0 / 1050.0);
}
// Otherwise, configure a windowed display
else {
dbSetDisplayModeAntialias(1280, 800, 32, 1, 0, 0);
dbSetCameraAspect(0, 1280.0 / 800.0);
int winPosX = (dbDesktopWidth() - dbScreenWidth()) / 2;
int winPosY = (dbDesktopHeight() - dbScreenHeight()) / 2;
dbSetWindowPosition(winPosX, winPosY);
}
// Hide the mouse pointer; CEGUI handles this
dbHideMouse();
// This forces the timer to initialise
MyTimer *timer = &MyTimer::get();
float t;
// Create a new Game State - this is a general game controlling class
BiPlaneGameState *gsGame = new BiPlaneGameState();
// We'll need a start-up menu
StartMenuGameState *gsMenu = new StartMenuGameState();
// a Loop State holder
bool loopState = TRUE;
// This is for the Start Menu loop
//while (LoopGDK()) {
do {
// Tick the timer & frame rate for this loop
timer->tick();
t = timer->getT();
dbText(0, 0, dbStr((float)(1.0 / t)));
loopState &= gsGame->update(t);
loopState &= gsMenu->update(t);
dbSync();
} while (loopState && LoopGDK());
switch (gsMenu->getState()) {
// Start Server
case 1 :
break;
// Start Client
case 2 :
break;
// SOMETHING WENT WRONG!!
default : exit(-5);
}
loopState = TRUE;
// our main loop
//while (LoopGDK()) {
do {
// Tick the timer & frame rate for this loop
timer->tick();
t = timer->getT();
dbText(0, 0, dbStr((float)(1.0 / t)));
// Issue an Update to the GameState system, passing the frameTime into it
loopState &= gsGame->update(t);
// Update the display
dbSync();
} while (loopState && LoopGDK());
// Do a little house keeping
delete gsGame;
delete gsMenu;
return;
}
示例13: optimize
void VariationalBayes::optimize(bool verbose,OPT_TYPE method,long maxIter,double ftol, double gtol){//{{{
bool usedSteepest;
long iteration=0,i,r;
double boundOld,bound,squareNorm,squareNormOld=1,valBeta=0,valBetaDiv,natGrad_i,gradGamma_i,phiGradPhiSum_r;
double *gradPhi,*natGrad,*gradGamma,*searchDir,*tmpD,*phiOld;
gradPhi=natGrad=gradGamma=searchDir=tmpD=phiOld=NULL;
MyTimer timer;
// allocate stuff {{{
//SimpleSparse *phiGradPhi=new SimpleSparse(beta);
gradPhi = new double[T];
// phiOld = new double[T]; will use gradPhi memory for this
phiOld = NULL;
natGrad = new double[T];
if(method == OPTT_HS)
gradGamma = new double[T];
searchDir = new double[T];
//searchDirOld = new double[T];
//phiGradPhi_sum = new double[N];
// }}}
#ifdef LOG_CONV
ofstream logF(logFileName.c_str());
logF.precision(15);
logF<<"# iter bound squareNorm time(m) [M*means M*vars]"<<endl;
if(logTimer)logTimer->setQuiet();
#ifdef LONG_LOG
vector<double> dirAlpha(M);
#endif
#endif
boundOld=getBound();
timer.start();
while(true){
negGradient(gradPhi);
// "yuck"
//setVal(phiGradPhi,i,phi->val[i]*gradPhi[i]);
//phiGradPhi->sumRows(phiGradPhi_sum);
// removed need for phiGradPhi matrix:
// removed need for phiGradPhi_sum
/*for(r=0;r<N;r++){
phiGradPhi_sum[r] = 0;
for(i=phi->rowStart[r];i<phi->rowStart[r+1];i++) phiGradPhi_sum[r] += phi->val[i] * gradPhi[i];
}*/
// set natGrad & gradGamma
squareNorm=0;
valBeta = 0;
valBetaDiv = 0;
#pragma omp parallel for private(i,phiGradPhiSum_r,natGrad_i,gradGamma_i) reduction(+:squareNorm,valBeta,valBetaDiv)
for(r=0;r<N;r++){
phiGradPhiSum_r = 0;
for(i = phi->rowStart[r]; i < phi->rowStart[r+1]; i++)
phiGradPhiSum_r += phi->val[i] * gradPhi[i];
for(i = phi->rowStart[r]; i < phi->rowStart[r+1]; i++){
natGrad_i = gradPhi[i] - phiGradPhiSum_r;
gradGamma_i = natGrad_i * phi->val[i];
squareNorm += natGrad_i * gradGamma_i;
if(method==OPTT_PR){
valBeta += (natGrad_i - natGrad[i])*gradGamma_i;
}
if(method==OPTT_HS){
valBeta += (natGrad_i-natGrad[i])*gradGamma_i;
valBetaDiv += (natGrad_i-natGrad[i])*gradGamma[i];
gradGamma[i] = gradGamma_i;
}
natGrad[i] = natGrad_i;
}
}
if((method==OPTT_STEEPEST) || (iteration % (N*M)==0)){
valBeta=0;
}else if(method==OPTT_PR ){
// already computed:
// valBeta=0;
// for(i=0;i<T;i++)valBeta+= (natGrad[i]-natGradOld[i])*gradGamma[i];
valBeta /= squareNormOld;
}else if(method==OPTT_FR ){
valBeta = squareNorm / squareNormOld;
}else if(method==OPTT_HS ){
// already computed:
//valBeta=div=0;
//for(i=0;i<T;i++){
// valBeta += (natGrad[i]-natGradOld[i])*gradGamma[i];
// div += (natGrad[i]-natGradOld[i])*gradGammaOld[i];
//}
if(valBetaDiv!=0)valBeta /= valBetaDiv;
else valBeta = 0;
}
if(valBeta>0){
usedSteepest = false;
//for(i=0;i<T;i++)searchDir[i]= -natGrad[i] + valBeta*searchDirOld[i];
// removed need for searchDirOld:
#pragma omp parallel for
for(i=0;i<T;i++)
searchDir[i]= -natGrad[i] + valBeta*searchDir[i];
}else{
usedSteepest = true;
#pragma omp parallel for
for(i=0;i<T;i++)
//.........这里部分代码省略.........
示例14: main
//------------------------------------------------------------------------------
int main(int argc, char *argv[]) {
if (argc == 3) {
TestReader::Tests tests;
if ( TestReader::read(argv[1], tests) ) {
std::ofstream ofl(argv[2], std::ios_base::out | std::ios_base::trunc);
if (ofl) {
RankerCfg rankerCfg;
rankerCfg.setBegin(0);
rankerCfg.setEnd(1000);
rankerCfg.setCount(THREADS_NUM);
auto const ranks = Ranker::doRank(rankerCfg);
std::cout << "Threads count = " << THREADS_NUM << std::endl;
MyTimer allTestsTimer;
for (size_t i = 0, n = tests.size(); i < n; ++i) {
MyTimer testTimer;
auto const test = tests[i];
std::cout << "Test#" << i << " bombs : [ ";
for (auto const &bomb : test) {
std::cout << "(x : " << bomb.x()
<< ", y : " << bomb.y()
<< ", z : " << bomb.z() << ") ";
}
std::cout << "]" << std::endl;
std::vector< WorkerPtr > workers;
for (auto const rank : ranks) {
WorkerCfg workerCfg;
workerCfg.setSideSize(1000);
workerCfg.setXBegin(rank.first);
workerCfg.setXEnd(rank.second);
workerCfg.setTest(test);
auto worker = std::make_shared< Worker >(workerCfg);
workers.push_back(worker);
auto thread = std::thread( &Worker::execute, worker.get() );
thread.detach();
}
Maxer< int > maxDistanceSquared(-1);
for (auto const &worker : workers) {
auto const safeDistanceSquared = worker->safeDistanceSquared();
maxDistanceSquared.setValue(safeDistanceSquared);
}
// write to file
ofl << maxDistanceSquared.value() << std::endl;
std::cout << "Safe distance squared = " << maxDistanceSquared.value()
<< std::endl;
std::cout << "Test#" << i << " duration " << testTimer.elapsedMs()
<< " ms" << std::endl;
std::cout << "--------" << std::endl;
}
std::cout << "All tests duration " << allTestsTimer.elapsedMs()
<< " ms" << std::endl;
}
} else {
std::cerr << "Fail open output file " << argv[2] << std::endl;
}
} else {
std::cout << "Use " << argv[0] << " <input-file> <output-file>"
<< std::endl;
}
}
示例15: operator
void operator()(MyTimer& timer) {
typename Container::Element elem;
container_.reserve(LOOPSIZE);
timer.stop(); // end of construct part
timer.start("push_back part");
timer.pause();
for (int i=0; i<LOOPSIZE; ++i) {
elem.fill_rand(); // timer ignores the time consumption of this function call
timer.resume();
container_.push_back(elem);
timer.pause();
}
timer.stop(); // end of push_back part
timer.start("sort part");
container_.sort();
timer.stop(); // end od sort part
std::cout << "container size before unique: " << container_.size() << std::endl;
timer.start("unique part");
container_.unique();
timer.stop(); // end of uniue part
std::cout << "container size after unique: " << container_.size() << std::endl;
timer.start("destruct part");
}