本文整理汇总了C++中CPUTimer::start方法的典型用法代码示例。如果您正苦于以下问题:C++ CPUTimer::start方法的具体用法?C++ CPUTimer::start怎么用?C++ CPUTimer::start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CPUTimer
的用法示例。
在下文中一共展示了CPUTimer::start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: benchmark_ts_clustercoeff
void benchmark_ts_clustercoeff(tsppi::TsPpiGraph& tsppi)
{
CPUTimer timer;
double naive_time, fast_time, faster_time;
LOG("Start Benchmark: Naive");
timer.start();
std::vector<std::vector<double> > naive_ts_bw = tsppi::algo::subgraph_cc(tsppi.subgraphs);
timer.stop();
naive_time = timer.getTime();
LOG("Time for Naive: " << timer.getTime() << " s");
LOG("Start Benchmark: Fast");
timer.start();
std::vector<std::vector<double> > fast_ts_bw = tsppi::algo::subgraph_cc_neighbor_comb(tsppi.subgraphs);
timer.stop();
fast_time = timer.getTime();
LOG("Time for Fast: " << timer.getTime() << " s");
LOG("Start Benchmark: Fast");
timer.start();
std::vector<std::vector<double> > faster_ts_bw = tsppi::algo::subgraph_cc_neighbor_comb_vec(tsppi.subgraphs);
timer.stop();
faster_time = timer.getTime();
LOG("Time for Fast: " << timer.getTime() << " s");
std::cout << naive_time << ";" << fast_time << ";" << faster_time;
}
示例2: benchmark_ts_PLP
void benchmark_ts_PLP(tsppi::TsPpiGraph& tsppi, bool printHist=false)
{
CPUTimer timer;
double naive_time, fast_time;
LOG("Start Benchmark: Naive");
timer.start();
std::vector<NetworKit::Partition > partitions = tsppi::algo::subgraph_PLP(tsppi.subgraphs);
timer.stop();
naive_time = timer.getTime();
LOG("Time for Naive: " << timer.getTime() << " s");
LOG("Start Benchmark: Fast");
timer.start();
std::vector<NetworKit::Partition > partitions_2 = tsppi::algo::subgraph_PLP_vec(tsppi.subgraphs);
timer.stop();
fast_time = timer.getTime();
LOG("Time for Fast: " << timer.getTime() << " s");
// print histogram
if (printHist)
{
std::cout << "Histogram of cluster sizes for Naive:" << std::endl;
clusterSizeHist(partitions);
std::cout << "Histogram of cluster sizes for fast:" << std::endl;
clusterSizeHist(partitions_2);
}
// print timings
std::cout << naive_time << ";" << fast_time;
}
示例3: main
int main(int argc, const char * argv[])
{
int numberOfIterations = MAX_K;
if (argc > 1)
numberOfIterations = atoi(argv[1]);
CPUTimer timer;
int totalRuns = 0;
cout << "Initializing computation for different values of k:" << endl;
cout << "Trying to generate rounds for k from 0 to " << numberOfIterations << endl;
cout << "Printing rounds output for k <= " << MAX_K_TO_PRINT_RESULTS << endl;
cout << "----------------------------------------------------" << endl;
timer.start();
for (int k = 0; k <= numberOfIterations; k++)
{
CPUTimer timerPerK;
int runsPerK=0;
string output;
do
{
timerPerK.start();
output = testAlgorithm(k, false);
timerPerK.stop();
totalRuns++;
runsPerK++;
} while ( timerPerK.getCPUTotalSecs() < 5.0 );
if (k <= MAX_K_TO_PRINT_RESULTS)
{
timerPerK.start();
output = testAlgorithm(k, true);
timerPerK.stop();
totalRuns++;
runsPerK++;
}
cout << endl << "Results for k=" << k << ":" << endl << endl;
int numTeams, numRounds, numMatches;
calculateDataSize(k,&numTeams,&numRounds,&numMatches);
cout << "\t" << numTeams << " teams." << endl;
cout << "\t" << numRounds << " rounds with " << numTeams / 2 << " matches per round." << endl;
cout << "\t" << numMatches << " total number of matches." << endl << endl;
cout << "\t" << runsPerK << " runs in " << timerPerK.getCPUTotalSecs() << "s" << endl;
cout << "\t" << "Average time per run: " << timerPerK.getCPUTotalSecs() / runsPerK << "s" << endl;
cout << output;
}
timer.stop();
cout << "Total time: " << timer.getCPUTotalSecs() << "s" << endl;
cout << "Average time per run : " << timer.getCPUTotalSecs() / (double)totalRuns << "s" << endl;
}
示例4: insert
int insert(bst * h, char * str){
bst_ret ret;
char * new_str = (char *) malloc(strlen(str) + 1);
if(new_str == NULL){
printf("ERROR: No memory for new string!\n");
exit(1);
}
strcpy(new_str, str);
/* Insert into Hash Table */
insTime.start();
ret = bst_insert(h, new_str);
insTime.stop();
if(ret == bst_NoMem){
printf("ERROR: No memory for new node!\n");
exit(1);
}
/* We could insert the set */
if(ret == bst_Ok)
return OP_OK;
/* We had already inserted the set */
if(ret == bst_PrevInserted){
free(new_str);
return PREV_INSERTED;
}
/* The hash table is full */
return BST_FULL;
}
示例5: search
int search(hash * h, char * str){
hash_ret ret;
searchTime.start();
ret = hash_search(h, str);
searchTime.stop();
if(ret == hash_Found)
return OP_OK;
return NOT_FOUND;
}
示例6: _delete
int _delete(hash * h, char * str){
hash_ret ret;
remTime.start();
ret = hash_remove(h, str);
remTime.stop();
if(ret == hash_NotFound)
return NOT_FOUND;
return OP_OK;
}
示例7: _delete
int _delete(bst * h, char * str){
bst_ret ret;
remTime.start();
ret = bst_remove(h, str);
remTime.stop();
if(ret == bst_NotFound)
return NOT_FOUND;
return OP_OK;
}
示例8: search
int search(bst * h, char * str){
bst_ret ret;
searchTime.start();
ret = bst_search(h, str);
searchTime.stop();
if(ret == bst_Found)
return OP_OK;
return NOT_FOUND;
}
示例9: benchmark_ts_betweenness
void benchmark_ts_betweenness(tsppi::TsPpiGraph& tsppi)
{
CPUTimer timer;
double naive_time, fast_time;
LOG("Start Benchmark: Naive");
timer.start();
std::vector<std::vector<double> > naive_ts_bw = tsppi::algo::subgraph_betweenness(tsppi.subgraphs);
timer.stop();
naive_time = timer.getTime();
LOG("Time for Naive: " << timer.getTime() << " s");
LOG("Start Benchmark: Fast");
timer.start();
std::vector<std::vector<double> > fast_ts_bw = tsppi::algo::subgraph_betweenness_fast(tsppi.subgraphs);
timer.stop();
fast_time = timer.getTime();
LOG("Time for Fast: " << timer.getTime() << " s");
std::cout << naive_time << ";" << fast_time;
}
示例10: run_all_periodic_test
void run_all_periodic_test(int nx, int ny, int nz, float hx, float hy, float hz, double tol)
{
BoundaryConditionSet bc;
set_bc(bc, BC_PERIODIC, 0);
Sol_PCGPressure3DDeviceD solver;
Grid3DDeviceD rhs, coeff;
init_rhs(rhs, nx, ny, nz, hx, hy, hz, -1, false); // init to sin waves, no axis
init_coeff(coeff, nx, ny, nz, hx, hy, hz);
init_solver(solver, rhs, coeff, bc, nx, ny, nz, hx, hy, hz);
init_search_vector(solver, nx, ny, nz, false); // init to zero
double residual;
CPUTimer timer;
timer.start();
UNITTEST_ASSERT_TRUE(solver.solve(residual,tol,1000));
timer.stop();
printf("%f sec\n", timer.elapsed_sec());
UNITTEST_ASSERT_EQUAL_DOUBLE(residual, 0, tol);
}
示例11: relax
bool
Sol_MultigridPressure3DBase::do_fmg(double tolerance, int max_iter, double &result_l2, double &result_linf)
{
CPUTimer timer;
timer.start();
clear_error();
int level_ncyc;
int level;
result_l2 = result_linf = 0;
apply_boundary_conditions(0);
double orig_l2=0, orig_linf=0;
restrict_residuals(0,0,
(convergence & CONVERGENCE_CALC_L2) ? &orig_l2 : 0,
(convergence & CONVERGENCE_CALC_LINF) ? &orig_linf : 0);
//printf("Error Before: l2 = %f, linf = %f\n", orig_l2, orig_linf);
double orig_error = (convergence & CONVERGENCE_CRITERIA_L2) ? orig_l2 :
(convergence & CONVERGENCE_CRITERIA_LINF) ? orig_linf : 1e20;
if (orig_error < tolerance) {
if (convergence & CONVERGENCE_CALC_L2) result_l2 = orig_l2;
if (convergence & CONVERGENCE_CALC_LINF) result_linf = orig_linf;
return true;
}
#if 0
// for testing relaxation only, enable this code block
double iter_l2, iter_linf;
for (int o=0; o < 100; o++) {
relax(0, 10, RO_SYMMETRIC);
restrict_residuals(0, 0, &iter_l2, &iter_linf);
printf("error: l2 = %.12f, linf = %.12f\n", iter_l2, iter_linf);
}
printf("reduction: l2 = %f, linf = %f\n", orig_l2/iter_l2, orig_linf/iter_linf);
result_l2 = iter_l2;
result_linf = iter_linf;
return true;
#endif
// initialize all the residuals.
// we need this because in the FMG loop below, we don't necessarily start at level 0, but
// rather 2 levels from the finest. Which means we first need to propagate the errors all the way down first before
// beginning FMG.
int coarse_level = _num_levels-1;
int num_vcyc = 0;
for (level = 0; level < _num_levels-1; level++) {
// initialize U (solution) at next level to zero
clear_zero(level+1);
apply_boundary_conditions(level+1);
// restrict residuals to the next level.
restrict_residuals(level, level+1,0,0);
}
// do the full-multigrid loop
for (int fine_level = _num_levels-1; fine_level >= 0 ; fine_level--) {
//{ int fine_level = 0; // do a single v-cycle instead
// we always do one extra v-cycle
level_ncyc = (fine_level == 0) ? max_iter+1 : 1;
// do ncyc v-cycle's
for (int i_cyc = 0; i_cyc < level_ncyc; i_cyc++) {
if (fine_level == 0)
num_vcyc++;
// going down
for (level = fine_level; level < coarse_level; level++) {
relax(level, nu1, RO_RED_BLACK);
clear_zero(level+1);
apply_boundary_conditions(level+1);
if (level == 0) {
restrict_residuals(0, 1,
(convergence & CONVERGENCE_CALC_L2) ? &result_l2 : 0,
(convergence & CONVERGENCE_CALC_LINF) ? &result_linf : 0);
double residual = (convergence & CONVERGENCE_CRITERIA_L2) ? result_l2 :
(convergence & CONVERGENCE_CRITERIA_LINF) ? result_linf : 1e20;
if (ThreadManager::this_image() == 0)
printf("%d: residual = %.12f,%.12f\n", i_cyc, result_linf, result_l2);
// if we're below tolerance, or we're no longer converging, bail out
if (residual < tolerance) {
// last time through, we need to apply boundary condition to u[0], since we just relaxed (above), but haven't propagated changes to ghost cells.
// in the case we are not finished, by the time we get back to level 0 (via coarsening & then prolongation), ghost cells would be filled in.
// but since we are bailing here, we need to explicitly make ghost cells up-to-date with u.
apply_boundary_conditions(0);
timer.stop();
//.........这里部分代码省略.........
示例12: main
/**
* Reads in the input file, performs the KP-frac linear time strategy on the
* input and displays the optimal solution.
*/
int main (int argc, char * argv[]) {
if (argc <= 1) {
std::cout << "Please indicate the name of the input file." << std::endl;
return -1;
}
CPUTimer timer;
std::cout << "Instance, Avg Running Time (s), Number of Iterations, Value" << std::endl;
for (int fileIdx = 1; fileIdx < argc; fileIdx++) {
parser(argv[fileIdx]);
Object * temp = new Object[num_elem];
for (int i = 0; i < num_elem; i++)
temp[i] = objects[i];
timer.reset();
int it = 0;
while (timer.getCPUTotalSecs() < 5.0)
{
inserted.clear();
timer.start();
kpfrac_linear(objects, num_elem, W);
timer.stop();
it++;
for(int j = 0; j < num_elem; j++)
objects[j] = temp[j];
}
double media = timer.getCPUTotalSecs() / it;
std::cout << argv[fileIdx] << "," << media << "," << it;
// Loop over the array of objects and display which were inserted and with
// what frequency.
double totalValue = 0;
#ifdef DEBUG
std::cout << "Elem | Value | Weight | Density | Frequency" << std::endl;
#endif
for (int i = 0, len = inserted.size(); i < len; i++) {
Object obj = inserted[i];
#ifdef DEBUG
std::cout << "Elem | Value | Weight | Density | Frequency" << std::endl;
std::cout << obj.elem << " " << obj.value << " "
<< obj.weight << " " << obj.density << " "
<< obj.frequency << std::endl;
#endif
totalValue += obj.frequency * obj.value;
}
std::cout << std::setprecision(15) << "," << totalValue << std::endl;
delete [] objects;
inserted.clear();
}
return 0;
}
示例13: run_resolution
void run_resolution(int res, double dt, double t1, double Ra, double Pr, bool do_diagnostic=true) {
Eqn_IncompressibleNS3DParamsD params;
Eqn_IncompressibleNS3DD eqn;
init_params(params, res, Ra, Pr);
UNITTEST_ASSERT_TRUE(eqn.set_parameters(params));
int next_frame = 1;
CPUTimer clock;
CPUTimer step_clock;
int step_count;
int start_count=0;
start_count = eqn.num_steps;
clock.start();
global_timer_clear_all();
step_count = eqn.num_steps;
step_clock.start();
set_forge_ahead(true);
for (double t = 0; t <= t1; t += dt) {
UNITTEST_ASSERT_TRUE(eqn.advance_one_step(dt));
if (do_diagnostic) {
double max_u, max_v, max_w;
eqn.get_u().reduce_maxabs(max_u);
eqn.get_v().reduce_maxabs(max_v);
eqn.get_w().reduce_maxabs(max_w); // not used in any calculations, but useful for troubleshooting
printf("> Max u = %.12f, Max v = %.12f, Max w = %.12f\n", max_u, max_v, max_w);
fflush(stdout);
if (t > next_frame * t1/100) {
char buff[1024];
sprintf(buff, "output.%04d.ppm", next_frame);
printf("%s\n", buff);
write_slice(buff, eqn.get_temperature());
next_frame++;
}
}
else {
if (t > next_frame * t1/100) {
step_clock.stop();
printf("ms/step = %f\n", step_clock.elapsed_ms() / (eqn.num_steps - step_count));
char buff[1024];
sprintf(buff, "output.%04d.ppm", next_frame);
global_counter_print();
global_counter_clear_all();
printf("%s\n", buff);
write_slice(buff, eqn.get_temperature());
next_frame++;
step_count = eqn.num_steps;
step_clock.start();
}
printf("%.4f%% done\r", t/t1 * 100);
}
}
clock.stop();
printf("Elapsed sec: %.8f\n", clock.elapsed_sec());
printf("ms/step = %f\n", clock.elapsed_ms() / (eqn.num_steps - start_count));
printf("\n............ DONE ...............\n\n");
}
示例14: model
void Instance::optKara2007()
{
CPUTimer t;
t.start();
int size = Gifts.size();
double totalWeight = 0;
for (int i = 0; i < (int)Gifts.size(); i++)
{
totalWeight += Gifts[i].weight;
}
cout << "Optimizing Instance by Kara2007 Two-Index One-Commodity Flow Integer Model to CPLEX..." << endl;
cout << "Number of Gifts:\t" << size << endl;
vector<vector<double> > c(size+1);
for (int i = 0; i < size+1; i++)
{
c[i].resize(size+1);
}
for (int i = 0; i < size+1; i++)
{
for (int j = i+1; j < size+1; j++)
{
c[i][j] = getDistance(getGiftId(i), getGiftId(j));
c[j][i] = c[i][j];
}
}
IloEnv env;
IloModel model(env);
IloObjective obj = IloMinimize(env);
NumVarMatrix var_x(env);
NumVarMatrix var_f(env);
string varName;
string consName;
for (int i = 0; i < size+1; i++)
{
var_x.add(IloNumVarArray(env));
var_f.add(IloNumVarArray(env));
}
varName = "K";
IloNumVar var_K(env, 1, size, IloNumVar::Int, (char*)varName.c_str());
for (int i = 0; i < size+1; i++)
{
for (int j = 0; j < size+1; j++)
{
varName = "x" + to_string(getGiftId(i)) + "_" + to_string(getGiftId(j));
var_x[i].add( IloNumVar(env, 0, 1, IloNumVar::Int, (char*)varName.c_str()) );
varName = "f" + to_string(getGiftId(i)) + "_" + to_string(getGiftId(j));
var_f[i].add( IloNumVar(env, 0, 1010, IloNumVar::Float, (char*)varName.c_str()) );
}
}
for (int i = 0; i < size+1; i++)
{
for (int j = 0; j < size+1; j++)
{
obj.setLinearCoef(var_x[i][j], 10*c[i][j]);
obj.setLinearCoef(var_f[i][j], c[i][j]);
}
}
model.add(obj);
//numeracao segundo Fukasawa 2015
// (1a) - tudo que sai de todo i
for (int i = 0; i < size; i++)
{
consName = "c1a_" + to_string(getGiftId(i));
IloRange c1a(env, 1, 1, (char*)consName.c_str());
for (int j = 0; j < size+1; j++)
{
if (c[i][j] > 0)
{
c1a.setLinearCoef(var_x[i][j], 1);
}
}
model.add(c1a);
}
// (1b) - tudo que entra em todo i
for (int i = 0; i < size; i++)
{
consName = "c1b_" + to_string(getGiftId(i));
IloRange c1b( env, 1, 1, (char*)consName.c_str() );
for (int j = 0; j < size+1; j++)
{
if (c[i][j] > 0)
{
c1b.setLinearCoef(var_x[j][i], 1);
}
}
//.........这里部分代码省略.........
示例15: main
//.........这里部分代码省略.........
float z = k*pdata.dzdi+zmin;
float Ex = -1.0*x;
fields.getE(i,j,k,0) = 0;
fields.getE(i,j,k,1) = Ey;
fields.getE(i,j,k,2) = 0;
fields.getB(i,j,k,0) = 0;
fields.getB(i,j,k,1) = 0;
fields.getB(i,j,k,2) = Bz;
// printf("fields(%i,%i,%i) = %f, %f, %f\n",i,j,k,
// fields.getE(i,j,k,0),fields.getE(i,j,k,1),fields.getE(i,j,k,2));
}
}
}
fields.q2m[0] = 1.0;
printf("Efield setup complete\n");
float time;
double avg_error = 0.0;
int n_error = 0;
CPUTimer timer;
moments->init_plot();
timer.start();
for(int i=0;i<steps;i++)
{
//time = dtau0*(i);
//moments.set_vals(0);
particles.push(&pdata,&fields,moments);
printf("finished step %i\n",i);
for(int j=0;j<nptcls;j++)
{
float px,py,gx,gy;
float rl;
float vx,vy,vxy,vz,vxyz;
float vgx,vgy;
float verror;
px = (particles.px[j] + particles.ix[j])*pdata.dxdi + pdata.xmin;
py = (particles.py[j] + particles.iy[j])*pdata.dydi + pdata.ymin;
vx = particles.vx[j];
vy = particles.vy[j];
vz = particles.vz[j];
vxy = sqrt(vx*vx+vy*vy);
vxyz = sqrt(vxy*vxy + vz*vz);
rl = vxy/Bz;