static void display() {static int n; glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glLoadIdentity(); static glShaderManager SM; static glShader *shader; if(!n) { shader= SM.loadfromFile("vert2.txt","frag2.txt"); } static timer t; double t2=t.elapsed(); glPointSize(23); static vector< particule> v; Repere(); if(!n) { for(int i=0;i<2000;i++) { v.push_back(particule(45,20,8,1,i)); } } shader->begin(); int c=v.size(); for(int i=0;i<c;i++) { shader->setUniform1f("p.alpha",v[i].getAlpha(),shader->GetUniformLocation("p.alpha")); shader->setUniform1f("p.beta",v[i].getBeta(),shader->GetUniformLocation("p.beta")); shader->setUniform1f("p.vIn",v[i].getInitV(),shader->GetUniformLocation("p.vIn")); shader->setUniform1f("p.t",t2/2,shader->GetUniformLocation("p.t")); shader->setUniform1f("p.start",v[i].getStart(),shader->GetUniformLocation("p.start")); shader->setUniform1f("p.life",v[i].getLife(),shader->GetUniformLocation("p.life")); v[i].draw(0,0,0); } shader->end(); n++; if(n>2) n=1; glutSwapBuffers(); }
void push(Queue& queue, size_t n, timer& t) { t.restart(); for(size_t i=0; i<n; i++) queue.push(); t.stop(); }
std::future<bool> send(core::const_frame frame) override { CASPAR_VERIFY(format_desc_.height * format_desc_.width * 4 == frame.image_data(0).size()); graph_->set_value("tick-time", tick_timer_.elapsed() * format_desc_.fps * 0.5); tick_timer_.restart(); caspar::timer frame_timer; { auto audio_buffer = core::audio_32_to_16(frame.audio_data()); airsend::add_audio(air_send_.get(), audio_buffer.data(), static_cast<int>(audio_buffer.size()) / format_desc_.audio_channels); } { connected_ = airsend::add_frame_bgra(air_send_.get(), frame.image_data(0).begin()); } graph_->set_text(print()); graph_->set_value("frame-time", frame_timer.elapsed() * format_desc_.fps * 0.5); return make_ready_future(true); }
int diagonalize_bisection(localized_matrix<double, MATRIX_MAJOR>& mata, localized_matrix<double, MATRIX_MAJOR>& matb, double* eigvals, rokko::parameters const& params, timer& timer) { rokko::parameters params_out; char jobz = 'N'; // only eigenvalues int dim = mata.innerSize(); int lda = mata.outerSize(); int ldb = matb.outerSize(); lapack_int m; // output: found eigenvalues double abstol; get_key(params, "abstol", abstol); if (abstol < 0) { std::cerr << "Error in diagonalize_bisection" << std::endl << "abstol is negative value, which means QR method." << std::endl << "To use dsygvx as bisection solver, set abstol a positive value" << std::endl; throw; } if (!params.defined("abstol")) { // default: optimal value for bisection method abstol = 2 * LAPACKE_dlamch('S'); } params_out.set("abstol", abstol); char uplow = get_matrix_part(params); lapack_int il, iu; double vl, vu; char range = get_eigenvalues_range(params, vl, vu, il, iu); std::vector<lapack_int> ifail(dim); timer.start(timer_id::diagonalize_diagonalize); int info; if(mata.is_col_major()) info = LAPACKE_dsygvx(LAPACK_COL_MAJOR, 1, jobz, range, uplow, dim, &mata(0,0), lda, &matb(0,0), ldb, vl, vu, il, iu, abstol, &m, eigvals, NULL, lda, &ifail[0]); else info = LAPACKE_dsygvx(LAPACK_ROW_MAJOR, 1, jobz, range, uplow, dim, &mata(0,0), lda, &matb(0,0), ldb, vl, vu, il, iu, abstol, &m, eigvals, NULL, lda, &ifail[0]); timer.stop(timer_id::diagonalize_diagonalize); timer.start(timer_id::diagonalize_finalize); if (info) { std::cerr << "error at dsygvx function. info=" << info << std::endl; if (info < 0) { std::cerr << "This means that "; std::cerr << "the " << abs(info) << "-th argument had an illegal value." << std::endl; } exit(1); } params_out.set("m", m); params_out.set("ifail", ifail); if (params.get_bool("verbose")) { print_verbose("dsygvx (bisection)", jobz, range, uplow, vl, vu, il, iu, params_out); } timer.stop(timer_id::diagonalize_finalize); return info; }
/** * Prepare and runTimer a single statement of SQL. */ void prepareAndRun(sqlite3 *db, string stmt, timer &t) { sqlite3_stmt *pStmt; t.start(); checkErr(sqlite3_prepare_v2(db, stmt.c_str(), -1, &pStmt, NULL), __LINE__, db, stmt); while (checkErr(sqlite3_step(pStmt), __LINE__, db, stmt) == SQLITE_ROW); checkErr(sqlite3_finalize(pStmt), __LINE__, db, stmt); t.end(); }
int main() { vector<recorder<timer> > stats(2); for(int i = 0; i < 2; i++) stats[i].reset(); int size = 1000000; Resistive gh(6); //for(int i =0; i < size; i++) // gh.addEdge(i, i+1, i+1); //for(int i = 0; i < size; i++) // gh.addEdge(0, 1, i+1); // for(int i = 0; i < size; i++) { // for(int jazz = 0; jazz < 1000; jazz++) // gh.addEdge(i, i+1, 100); // } gh.addEdge(0, 1, 2); gh.addEdge(0, 1, 8); gh.addEdge(0, 5, 10); gh.addEdge(0, 2, 20); gh.addEdge(0, 2, 30); gh.addEdge(0, 2, 60); gh.addEdge(1, 3, 9); gh.addEdge(1, 3, 6); gh.addEdge(2, 4, 90); gh.addEdge(3, 5, 3); gh.addEdge(4, 5, 3); gh.addEdge(4, 5, 100); gh.addEdge(4, 5, 15); gh.printGraph(); timer1.restart(); double ans = gh.traverse(0, 5); timer1.stop(); stats[0].record(timer1); cout << "-----------------" << endl; gh.printGraph(); // print the adjacency list representation of the above graph cout << endl << "TIME: "; stats[0].report(cout); cout << endl << ans << endl; double test = 0; for(int n = 1; n <= size; n++) test += n; return 0; }
void Compute(graph<vertex>& GA, commandLine P) { t1.start(); long start = P.getOptionLongValue("-r",0); if(GA.V[start].getOutDegree() == 0) { cout << "starting vertex has degree 0" << endl; return; } const uintE K = P.getOptionIntValue("-K",10); const uintE N = P.getOptionIntValue("-N",10); const double t = P.getOptionDoubleValue("-t",3); srand (time(NULL)); uintE seed = rand(); const intE n = GA.n; //walk length probabilities double* fact = newA(double,K); fact[0] = 1; for(long k=1;k<K;k++) fact[k] = k*fact[k-1]; double* probs = newA(double,K); for(long k=0;k<K;k++) probs[k] = exp(-t)*pow(t,k)/fact[k]; unordered_map<uintE,double> p; for(long i=0;i<N;i++) { double randDouble = (double) hashInt(seed++) / UINT_E_MAX; long j = 0; double mass = 0; uintE x = start; do { mass += probs[j]; if(randDouble < mass) break; x = walk(x,GA.V,seed++); j++; } while(j <= K); p[x]++; } for(auto it=p.begin();it!=p.end();it++) { p[it->first] /= N; } free(probs); free(fact); t1.stop(); pairIF* A = newA(pairIF,p.size()); long numNonzerosQ = 0; for(auto it = p.begin(); it != p.end(); it++) { A[numNonzerosQ++] = make_pair(it->first,it->second); } sweepObject sweep = sweepCut(GA,A,numNonzerosQ,start); free(A); cout << "number of vertices touched = " << p.size() << endl; cout << "number of edges touched = " << sweep.vol << endl; cout << "conductance = " << sweep.conductance << " |S| = " << sweep.sizeS << " vol(S) = " << sweep.volS << " edgesCrossing = " << sweep.edgesCrossing << endl; t1.reportTotal("computation time"); }
int main(int argc, const char *argv[]) { logstream(LOG_WARNING)<<"CE_Graph parsers library is written by Danny Bickson (c). Send any " " comments or bug reports to [email protected] " << std::endl; global_logger().set_log_level(LOG_INFO); global_logger().set_log_to_console(true); CE_Graph_init(argc, argv); debug = get_option_int("debug", 0); dir = get_option_string("file_list"); lines = get_option_int("lines", 0); omp_set_num_threads(get_option_int("ncpus", 1)); mytime.start(); FILE * f = fopen(dir.c_str(), "r"); if (f == NULL) logstream(LOG_FATAL)<<"Failed to open file list!"<<std::endl; while(true){ char buf[256]; int rc = fscanf(f, "%s\n", buf); if (rc < 1) break; in_files.push_back(buf); } if (in_files.size() == 0) logstream(LOG_FATAL)<<"Failed to read any file names from the list file: " << dir << std::endl; #pragma omp parallel for for (uint i=0; i< in_files.size(); i++) parse(i); std::cout << "Finished in " << mytime.current_time() << std::endl << "\t direct tweets found: " << links_found << " \t global tweets: " << wide_tweets << "\t http links: " << http_links << "\t retweets: " << retweet_found << "\t total lines in input file : " << total_lines << " \t invalid records (missing names) " << missing_names << std::endl; save_map_to_text_file(string2nodeid, outdir + "map.text"); save_map_to_text_file(nodeid2hash, outdir + "reverse.map.text"); save_map_to_text_file(tweets_per_user, outdir + "tweets_per_user.text"); out_file fout("mm.info"); fprintf(fout.outf, "%%%%MatrixMarket matrix coordinate real general\n"); fprintf(fout.outf, "%u %u %lu\n", maxfrom+1, maxto+1, links_found); return 0; }
~scoped_timer() { if (enabled) { const double x = t.lap_ms(); std::cerr << "timed region `" << region << "' took " << x << " ms" << std::endl; } }
/** * Called after an iteration has finished. */ void after_iteration(int iteration, graphchi_context &ginfo) { logstream(LOG_DEBUG)<<mytimer.current_time() << "iteration: " << iteration << " changes: " << changes << std::endl; if (changes == 0) ginfo.set_last_iteration(iteration); changes = 0; iter++; }
bool ripng_router::check_startup() { if (!router::check_startup()) return false; int sock = socket(PF_INET6, SOCK_DGRAM, 0); if (sock < 0) return false; sockaddr_in6 local; memset(&local, 0, sizeof(local)); local.sin6_family = AF_INET6; local.sin6_port = htons(522); if (bind(sock, (sockaddr *)&local, sizeof(local)) < 0) { if (should_log(WARNING)) log().perror("Failed to bind"); close(sock); return false; } if (!m_sock.register_fd(sock)) { close(sock); return false; } if (!m_sock.enable_mc_loop(false)) return false; g_mrd->mrib().install_listener(this); m_garbcol_timer.start(); return true; }
results measure(const Implementation& implementation) const { // Run a few times in an attempt to pull code pages into CPU // cache execute(implementation); execute(implementation); timer::duration elapsed{0}; unsigned result{0}; { const timer time; result = execute(implementation); elapsed = time.elapsed(); } return {elapsed, result}; }
int main(int argc, const char ** argv) { print_copyright(); /* CE_Graph initialization will read the command line arguments and the configuration file. */ CE_Graph_init(argc, argv); /* Metrics object for keeping track of performance counters and other information. Currently required. */ metrics m("item-cf2"); /* Basic arguments for application */ min_allowed_intersection = get_option_int("min_allowed_intersection", min_allowed_intersection); distance_metric = get_option_int("distance", JACCARD_WEIGHT); if (distance_metric != JACCARD_WEIGHT) logstream(LOG_FATAL)<<"--distance_metrix=XX should be one of:9= JACCARD_WEIGHT" << std::endl; debug = get_option_int("debug", 0); parse_command_line_args(); //if (distance_metric != JACKARD && distance_metric != AA && distance_metric != RA) // logstream(LOG_FATAL)<<"Wrong distance metric. --distance_metric=XX, where XX should be either 0) JACKARD, 1) AA, 2) RA" << std::endl; mytimer.start(); int nshards = convert_matrixmarket<EdgeDataType>(training, 0, 0, 3, TRAINING, true); assert(M > 0 && N > 0); //initialize data structure which saves a subset of the items (pivots) in memory adjcontainer = new adjlist_container(); /* Run */ ItemDistanceProgram program; CE_Graph_engine<VertexDataType, EdgeDataType> engine(training, nshards, true, m); set_engine_flags(engine); //open output files as the number of operating threads out_files.resize(number_of_omp_threads()); for (uint i=0; i< out_files.size(); i++){ char buf[256]; sprintf(buf, "%s.out%d", training.c_str(), i); out_files[i] = open_file(buf, "w"); } //run the program engine.run(program, niters); /* Report execution metrics */ if (!quiet) metrics_report(m); std::cout<<"Total item pairs compared: " << item_pairs_compared << " total written to file: " << written_pairs << std::endl; for (uint i=0; i< out_files.size(); i++) fclose(out_files[i]); std::cout<<"Created output files with the format: " << training << ".outXX, where XX is the output thread number" << std::endl; return 0; }
int main(int argc, const char ** argv) { print_copyright(); /* GraphChi initialization will read the command line arguments and the configuration file. */ graphchi_init(argc, argv); /* Metrics object for keeping track of performance counters and other information. Currently required. */ metrics m("itemsim2rating2"); /* Basic arguments for application */ min_allowed_intersection = get_option_int("min_allowed_intersection", min_allowed_intersection); debug = get_option_int("debug", 0); parse_command_line_args(); std::string similarity = get_option_string("similarity", ""); if (similarity == "") Rcpp::Rcerr<<"Missing similarity input file. Please specify one using the --similarity=filename command line flag" << std::endl; undirected = get_option_int("undirected", 1); Q = get_option_float("Q", Q); K = get_option_int("K"); mytimer.start(); vec unused; int nshards = convert_matrixmarket_and_item_similarity<edge_data>(training, similarity, 3, unused); assert(M > 0 && N > 0); //initialize data structure which saves a subset of the items (pivots) in memory adjcontainer = new adjlist_container(); //array for marking which items are conected to the pivot items via users. relevant_items = new bool[N]; /* Run */ ItemDistanceProgram program; graphchi_engine<VertexDataType, edge_data> engine(training, nshards, true, m); set_engine_flags(engine); out_file = open_file((training + "-rec").c_str(), "w"); //run the program engine.run(program, niters); /* Report execution metrics */ if (!quiet) metrics_report(m); Rcpp::Rcout<<"Total item pairs compared: " << item_pairs_compared << " total written to file: " << written_pairs << std::endl; if (zero_edges) Rcpp::Rcout<<"Found: " << zero_edges<< " user edges with weight zero. Those are ignored." <<std::endl; delete[] relevant_items; fclose(out_file); return 0; }
int main(int argc, const char *argv[]) { logstream(LOG_WARNING)<<"GraphChi parsers library is written by Danny Bickson (c). Send any " " comments or bug reports to [email protected] " << std::endl; global_logger().set_log_level(LOG_INFO); global_logger().set_log_to_console(true); graphchi_init(argc, argv); debug = get_option_int("debug", 0); dir = get_option_string("file_list"); lines = get_option_int("lines", 0); omp_set_num_threads(get_option_int("ncpus", 1)); from_val = get_option_int("from_val", from_val); to_val = get_option_int("to_val", to_val); mid_val = get_option_int("mid_val", mid_val); if (from_val == -1) logstream(LOG_FATAL)<<"Must set from/to " << std::endl; mytime.start(); FILE * f = fopen(dir.c_str(), "r"); if (f == NULL) logstream(LOG_FATAL)<<"Failed to open file list!"<<std::endl; while(true){ char buf[256]; int rc = fscanf(f, "%s\n", buf); if (rc < 1) break; in_files.push_back(buf); } if (in_files.size() == 0) logstream(LOG_FATAL)<<"Failed to read any file frommap from the list file: " << dir << std::endl; #pragma omp parallel for for (int i=0; i< (int)in_files.size(); i++) parse(i); std::cout << "Finished in " << mytime.current_time() << std::endl; save_map_to_text_file(frommap.string2nodeid, outdir + dir + "map.text"); return 0; }
timer(const timer& aOther) : iOwnerThread(aOther.iOwnerThread), iTimerObject(aOther.iOwnerThread.io_service()), iDuration_ms(aOther.iDuration_ms), iWaiting(false), iCancelling(false) { if (aOther.waiting()) again(); }
void training_rmse(int iteration, graphchi_context &gcontext){ last_training_rmse = dtraining_rmse; dtraining_rmse = 0; #pragma omp parallel for reduction(+:dtraining_rmse) for (int i=0; i< (int)M; i++){ dtraining_rmse += latent_factors_inmem[i].rmse; } dtraining_rmse = sqrt(dtraining_rmse / pengine->num_edges()); std::cout<< std::setw(10) << mytimer.current_time() << ") Iteration: " << std::setw(3) <<iteration<<" Training RMSE: " << std::setw(10)<< dtraining_rmse; }
int shrimp_gateway_impl::read_reply() { m_timer_status = 0; m_io_timer.start(); char* r = new char[10]; int rd = m_shrimp.Readv(r, 1, &m_timer_status); //printf("r: %i\n", r[0]); m_reply = r[0]; //printf("byte read %i\n", rd); return rd; }
timer::timer(const timer& aOther) : iIoTask(aOther.iIoTask), iHandlerProxy(new handler_proxy(*this)), iTimerObject(aOther.iIoTask.timer_io_service().native_object()), iDuration_ms(aOther.iDuration_ms), iEnabled(aOther.iEnabled), iWaiting(false), iInReady(false) { if (aOther.waiting()) again(); }
/** * Vertex update function - computes the least square step */ void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) { if (vertex.id() >= M) return; vertex_data & vdata = latent_factors_inmem[vertex.id()]; int howmany = N*knn_sample_percent; assert(howmany > 0 ); vec distances = vec::Zero(howmany); ivec indices = ivec(howmany); for (int i=0; i< howmany; i++){ indices[i]= -2; } std::vector<bool> curratings; curratings.resize(N); for(int e=0; e < vertex.num_edges(); e++) { //no need to calculate this rating since it is given in the training data reference curratings[vertex.edge(e)->vertex_id() - M] = true; } if (knn_sample_percent == 1.0){ for (uint i=M; i< M+N; i++){ if (curratings[i-M]) continue; vertex_data & other = latent_factors_inmem[i]; double dist; als_predict(vdata, other, 0, dist); indices[i-M] = i-M; distances[i-M] = dist; } } else for (int i=0; i<howmany; i++){ int random_other = ::randi(M, M+N-1); vertex_data & other = latent_factors_inmem[random_other]; double dist; als_predict(vdata, other, 0, dist); indices[i-M] = i-M; distances[i-M] = dist; } vec out_dist(num_ratings); ivec indices_sorted = reverse_sort_index2(distances, indices, out_dist, num_ratings); assert(indices_sorted.size() <= num_ratings); assert(out_dist.size() <= num_ratings); vdata.ids = indices_sorted; vdata.ratings = out_dist; if (debug) printf("Closest is: %d with distance %g\n", (int)vdata.ids[0], vdata.ratings[0]); if (vertex.id() % 1000 == 0) printf("Computing recommendaitons for user %d at time: %g\n", vertex.id()+1, mytimer.current_time()); }
int main(int argc, const char *argv[]) { Rcpp::Rcout<<"GraphChi parsers library is written by Danny Bickson (c). Send any " " comments or bug reports to [email protected] " << std::endl; global_logger().set_log_level(LOG_INFO); global_logger().set_log_to_console(true); graphchi_init(argc, argv); debug = get_option_int("debug", 0); dir = get_option_string("file_list"); lines = get_option_int("lines", 0); omp_set_num_threads(get_option_int("ncpus", 1)); mytime.start(); FILE * f = fopen(dir.c_str(), "r"); if (f == NULL) logstream(LOG_FATAL)<<"Failed to open file list!"<<std::endl; while(true){ char buf[256]; int rc = fscanf(f, "%s\n", buf); if (rc < 1) break; in_files.push_back(buf); } if (in_files.size() == 0) logstream(LOG_FATAL)<<"Failed to read any file names from the list file: " << dir << std::endl; //#pragma omp parallel for for (uint i=0; i< in_files.size(); i++) parse(i); std::cout << "Finished in " << mytime.current_time() << std::endl << "\t total lines in input file : " << total_lines << "\t max from: " << maxfrom << "\t max to: " <<maxto << std::endl; return 0; }
int shrimp_gateway_impl::send_command(const shrimp_command_t& command) { m_timer_status = 0; m_io_timer.start(); unsigned char* cmd = new unsigned char[3]; memcpy(cmd, command.to_buf(), command.get_size()); //printf("%i %i %i", cmd[0], cmd[1], cmd[2]); int wd = m_shrimp.Writev(command.to_buf(), command.get_size(), &m_timer_status); //printf("bytes sent %i\n", wd); return wd; }
void reportAll() { t0.reportTotal("preprocess"); t1.reportTotal("connected components"); t2.reportTotal("Ecc phase 1"); t3.reportTotal("sort by decreasing eccentricities"); t4.reportTotal("Ecc phase 2"); t5.reportTotal("total time excluding writing to file"); }
/*! Progress(theTimer, nodenum, numnodes, thePercent, 5, theTime, 60, "Reading dumpfile"); if either delta is exceeded, increase oPercent & oTime and report the progress return 1 if something is printed out, else return 0 */ int Progress(timer &iTimer, double iNum, double iMax, double &oPercent, double iPercentDelta, double &oTime, double iTimeDelta, string iMsg) { double percent = iNum/iMax*100.0; double newtime = iTimer.elapsed_time(); if (iNum == iMax || percent - oPercent > iPercentDelta || newtime-oTime > iTimeDelta) { double remaining = (iMax-iNum)/(iNum!=0?iNum:1)*newtime; double persec= iNum/newtime; char msg[4096]; sprintf(msg, "\r%s: %g%%; %g/%g items, %g secs, %g/sec, left: %g", /*datestring(), */iMsg.c_str(), percent, iNum, iMax, newtime, persec, remaining); cerr << msg << flush; oPercent=percent; oTime=newtime; return 1; } return 0; }
/** * Vertex update function. */ void update(CE_Graph_vertex<VertexDataType, EdgeDataType> &v, CE_Graph_context &gcontext) { if (debug) printf("Entered iteration %d with %d - edges %d\n", gcontext.iteration, v.id(), v.num_edges()); /* even iteration numbers: * 1) load a subset of items into memory (pivots) * 2) Find which subset of items needs to compared to the users */ if (gcontext.iteration % 2 == 0) { if (adjcontainer->is_pivot(v.id())){ adjcontainer->load_edges_into_memory(v); if (debug) printf("Loading pivot %d intro memory\n", v.id()); } } else { for (vid_t i=adjcontainer->pivot_st; i< adjcontainer->pivot_en; i++){ //since metric is symmetric, compare only to pivots which are smaller than this item id if (i >= v.id()) continue; dense_adj &pivot_edges = adjcontainer->adjs[i - adjcontainer->pivot_st]; //pivot is not connected to this item, continue if (get_val(pivot_edges.edges, v.id()) == 0) continue; double dist = adjcontainer->calc_distance(v, i, distance_metric); item_pairs_compared++; if (item_pairs_compared % 1000000 == 0) logstream(LOG_INFO)<< std::setw(10) << mytimer.current_time() << ") " << std::setw(10) << item_pairs_compared << " pairs compared " << std::endl; if (debug) printf("comparing %d to pivot %d distance is %lg\n", i+ 1, v.id() + 1, dist); if (dist != 0){ fprintf(out_files[omp_get_thread_num()], "%u %u %.12lg\n", v.id()+1, i+1, (double)dist);//write item similarity to file //where the output format is: //[item A] [ item B ] [ distance ] written_pairs++; } } }//end of iteration % 2 == 1 }//end of update function
/** * Vertex update function. */ void update(graphchi_vertex<VertexDataType, edge_data> &v, graphchi_context &gcontext) { if (debug) printf("Entered iteration %d with %d\n", gcontext.iteration, is_item(v.id()) ? (v.id() - M + 1): v.id()); /* Even iteration numbers: * 1) load a subset of users into memory (pivots) * 2) Find which subset of items is connected to the users */ if (gcontext.iteration % 2 == 0) { if (adjcontainer->is_pivot(v.id()) && is_user(v.id())) { adjcontainer->load_edges_into_memory(v); if (debug) printf("Loading pivot %d intro memory\n", v.id()); } } /* odd iteration number: * 1) For any item connected to a pivot item * compute itersection */ else { assert(is_item(v.id())); for (int i=0; i< v.num_edges(); i++) { if (!adjcontainer->is_pivot(v.edge(i)->vertex_id())) continue; if (debug) printf("comparing user pivot %d to item %d\n", v.edge(i)->vertex_id()+1 , v.id() - M + 1); adjcontainer->compute_ratings(v, v.edge(i)->vertex_id(), v.edge(i)->get_data().up_weight); item_pairs_compared++; if (item_pairs_compared % 1000000 == 0) Rcpp::Rcout<< std::setw(10) << mytimer.current_time() << ") " << std::setw(10) << item_pairs_compared << " pairs compared " << std::endl; } }//end of iteration % 2 == 1 }//end of update function
int main(int argc, const char ** argv) { /* GraphChi initialization will read the command line arguments and the configuration file. */ graphchi_init(argc, argv); /* Metrics object for keeping track of performance counters and other information. Currently required. */ metrics m("connected-components-inmem"); /* Basic arguments for application */ std::string filename = get_option_string("file"); // Base filename int niters = get_option_int("niters", 100); // Number of iterations (max) int output_labels = get_option_int("output_labels", 0); //output node labels to file? bool scheduler = true; // Always run with scheduler /* Process input file - if not already preprocessed */ float p = get_option_float("p", -1); int n = get_option_int("n", -1); int quiet = get_option_int("quiet", 0); if (quiet) global_logger().set_log_level(LOG_ERROR); int nshards = (int) convert_if_notexists<EdgeDataType>(filename, get_option_string("nshards", "auto")); mytimer.start(); /* Run */ ConnectedComponentsProgram program; graphchi_engine<VertexDataType, EdgeDataType> engine(filename, nshards, scheduler, m); engine.set_disable_vertexdata_storage(); engine.set_enable_deterministic_parallelism(false); engine.set_modifies_inedges(false); engine.set_modifies_outedges(false); engine.set_preload_commit(false); engine.set_maxwindow(engine.num_vertices()); mytimer.start(); active_nodes = new bool[engine.num_vertices()]; for (int i=0; i< engine.num_vertices(); i++) active_nodes[i] = true; engine.run(program, niters); /* Run analysis of the connected components (output is written to a file) */ if (output_labels){ FILE * pfile = fopen((filename + "-components").c_str(), "w"); if (!pfile) logstream(LOG_FATAL)<<"Failed to open file: " << filename << std::endl; fprintf(pfile, "%%%%MatrixMarket matrix array real general\n"); fprintf(pfile, "%lu %u\n", engine.num_vertices()-1, 1); for (uint i=1; i< engine.num_vertices(); i++){ fprintf(pfile, "%u\n", vertex_values[i]); assert(vertex_values[i] >= 0 && vertex_values[i] < engine.num_vertices()); } fclose(pfile); logstream(LOG_INFO)<<"Saved succesfully to out file: " << filename << "-components" << " time for saving: " << mytimer.current_time() << std::endl; } std::cout<<"Total runtime: " << mytimer.current_time() << std::endl; if (p > 0) std::cout << "site fraction p= " << p << std::endl; if (n > 0){ std::cout << "n=" << n*p << std::endl; std::cout << "isolated sites: " << p*(double)n-actual_vertices << std::endl; } std::cout << "Number of sites: " << actual_vertices << std::endl; std::cout << "Number of bonds: " << engine.num_edges() << std::endl; if (n){ std::cout << "Percentage of sites: " << (double)actual_vertices / (double)n << std::endl; std::cout << "Percentage of bonds: " << (double)engine.num_edges() / (2.0*n) << std::endl; } std::cout << "Number of iterations: " << iter << std::endl; std::cout << "SITES RESULT:\nsize\tcount\n"; std::map<uint,uint> final_countsv; std::map<uint,uint> final_countse; std::map<uint,uint> statv; for (int i=0; i< engine.num_vertices(); i++) statv[vertex_values[i]]++; uint total_sites = 0; for (std::map<uint, uint>::const_iterator iter = statv.begin(); iter != statv.end(); iter++) { //std::cout << iter->first << "\t" << iter->second << "\n"; final_countsv[iter->second] += 1; total_sites += iter->second; } for (std::map<uint, uint>::const_iterator iter = final_countsv.begin(); iter != final_countsv.end(); iter++) { std::cout << iter->first << "\t" << iter->second << "\n"; } edge_count = 1; engine.run(program, 1); std::cout << "BONDS RESULT:\nsize\tcount\n"; uint total_bonds = 0; for (std::map<uint, uint>::const_iterator iter = state.begin(); iter != state.end(); iter++) { //std::cout << iter->first << "\t" << iter->second << "\n"; final_countse[iter->second] += 1; total_bonds += iter->second; } for (std::map<uint, uint>::const_iterator iter = final_countse.begin(); iter != final_countse.end(); iter++) { std::cout << iter->first << "\t" << iter->second << "\n"; } assert(total_sites == graph.num_vertices()); assert(total_bonds == graph.num_edges()); return 0; }
// add a timer void add(timer const& t) { add(t.elapsed()); }
// For each container, determine how long it takes to return an iterator to the word luge. // For the vector and list class, use the STL algorithm lower bound. // For the set and unordered set class, use the container’s method find. class timer { public: timer() : start(clock()) {} double elapsed() { return ( clock() - start ) / CLOCKS_PER_SEC; } void reset() { start = clock(); } private: double start; }; timer t; double duration = t.elapsed(); string testWord = "luge"; // look up lower bound algorithms // look up how to do a find within sets andunordered sets. // also double check whether you can make open the ENABLE file!!! int main(){ // cout << "//======================================= PART TWO =======================================//" << endl; // // vector<Student> compVec{Student("Lisa"),Student("Jessica"), Student("Marie"), Student("Apple")}; // // meFirst myComp("Monty") ;
//------------------------------------------------------- int main( int argc, char **argv) { MPI::Init(argc, argv); rank = MPI::COMM_WORLD.Get_rank(); size = MPI::COMM_WORLD.Get_size(); // ----- Construction of a Cartesian topolog CartComm<2> cart(argc, argv, rank); Isub = cart.get_I(); Jsub = cart.get_J(); num_subdom_x = cart.getNumProc_I(); num_subdom_y = cart.getNumProc_J(); // cart.print(); // Reading and broadcasting data from the input file read_data_and_Bcast(cart); // Global Mesh StructuredMesh<Uniform<double, 2> > mesh(lx_g, num_nodes_x_g, ly_g, num_nodes_y_g); double dx = mesh.getDelta(X); double dy = mesh.getDelta(Y); // mesh.print(); /***/ // Subdomain SubDomain<double, 2> subdom(cart); double ovlp_l = subdom.createOverlap(LEFT, nc_ovlp_l, dx); double ovlp_r = subdom.createOverlap(RIGHT, nc_ovlp_r, dx); double ovlp_d = subdom.createOverlap(DOWN, nc_ovlp_d, dy); double ovlp_u = subdom.createOverlap(UP, nc_ovlp_u, dy); // Local mesh for subdomains of equal length length_x = lx_g / num_subdom_x; // Non-overlapping length_y = ly_g / num_subdom_y; // Non-overlapping // Restriction: (num_nodes_x_g - 1) % num_subdomx = 0 num_nodes_x = (num_nodes_x_g - 1) / num_subdom_x + 1; // Restriction: (num_nodes_y_g - 1) % num_subdomy = 0 num_nodes_y = (num_nodes_y_g - 1) / num_subdom_y + 1; // Adding the overlapping length_x += ovlp_l + ovlp_r; length_y += ovlp_d + ovlp_u; num_nodes_x += nc_ovlp_l + nc_ovlp_r; num_nodes_y += nc_ovlp_d + nc_ovlp_u; // Resizing the mesh to the local values for the subdomain mesh.resize(length_x, num_nodes_x, length_y, num_nodes_y); mesh.print(); // Define the info to be exchanged between subdomains subdom.setupInfoExchange(mesh); subdom.print(); double Gamma = permeability; ScalarField2D p ( mesh.getExtentVolumes() ); ScalarField2D Sw ( mesh.getExtentVolumes() ); ScalarField2D p_n( mesh.getExtentNodes() ); ScalarField2D Sw_n( mesh.getExtentNodes() ); // Initial conditions Sw = 0; p = pres_out; Range all = Range::all(); // Boundary condition Sw(0, all) = Sw_in; /** */ NumUtils::interpolateToNodes(p_n, p); NumUtils::interpolateToNodes(Sw_n, Sw); if (rank == 0) { InOut::writeToFile_DX(Sw_n, 0, "./DataBL/00/satu.", dx, dy); InOut::writeToFile_DX(p_n, 0, "./DataBL/00/pres.", dx, dy); } if (rank == 1) { InOut::writeToFile_DX(p_n, 0, "./DataBL/01/pres.", dx, dy); InOut::writeToFile_DX(Sw_n, 0, "./DataBL/01/satu.", dx, dy); } if (rank == 2) { InOut::writeToFile_DX(Sw_n, 0, "./DataBL/02/satu.", dx, dy); InOut::writeToFile_DX(p_n, 0, "./DataBL/02/pres.", dx, dy); } if (rank == 3) { InOut::writeToFile_DX(p_n, 0, "./DataBL/03/pres.", dx, dy); InOut::writeToFile_DX(Sw_n, 0, "./DataBL/03/satu.", dx, dy); } // SparseMatrix< Diagonal< double, 2> > A(num_nodes_x, num_nodes_y); DiagonalMatrix< double, 2> A(num_nodes_x, num_nodes_y); ScalarField2D b(num_nodes_x, num_nodes_y); TwoPhaseEquation< BLIP1<double, 2> > pressure(p, A, b, mesh.getDeltas()); pressure.setDeltaTime(dt); pressure.setPermeability(permeability); pressure.setPorosity(porosity); pressure.setSrw(Srw); pressure.setSro(Sro); pressure.setViscosity_w(mu_w); pressure.setViscosity_o(mu_o); pressure.setNeumann (LEFT_WALL, -injection * mu_w / permeability); pressure.setDirichlet(RIGHT_WALL); pressure.setNeumann (TOP_WALL); pressure.setNeumann (BOTTOM_WALL); pressure.setSaturation(Sw); pressure.print(); // // In these case, the boundary conditions are calculated in // the numerical scheme (the adaptor BLES1). // TwoPhaseEquation< BLES1<double, 2> > saturation(Sw, A, b, mesh.getDeltas()); saturation.setDeltaTime(dt); saturation.setPermeability(permeability); saturation.setPorosity(porosity); saturation.setSrw(Srw); saturation.setSro(Sro); saturation.setViscosity_w(mu_w); saturation.setViscosity_o(mu_o); saturation.applyBounds(1, Sw.ubound(firstDim)-1);// just to move the indexes saturation.setNeumann(TOP_WALL); saturation.setNeumann(BOTTOM_WALL); saturation.setPressure(p); saturation.print(); ofstream error_fp, residual_fp; if (rank == 0){ error_fp.open("./DataBL/00/error"); residual_fp.open ("./DataBL/00/residual"); } if (rank == 1) { error_fp.open("./DataBL/01/error"); residual_fp.open("./DataBL/01/residual"); } int iteration = 1, idprint = 1; double t = dt; double error = 1.0; double residual = 1.0; // int pausa; int bi = saturation.get_bi(), bj = saturation.get_bj(); int ei = saturation.get_ei(), ej = saturation.get_ej(); frequency *= (86400 / dt); double total_time = 0, pres_time = 0, sat_time = 0; while (t <= Tmax) { if ( !(iteration % idt_p) ) { crono.tic(); pressure.calcCoefficients(); Solver::TDMA2DX(pressure, tolerance, tdma_iter, 1.0); pres_time += crono.toc(); residual = pressure.calcResidual(); error = pressure.calcErrorL1(); error_fp << iteration << "\t" << error << std::endl; residual_fp << iteration << "\t" << residual << std::endl; pressure.update(); } crono.tic(); saturation.calcCoefficients(); Solver::solExplicit2D(saturation); sat_time += crono.toc(); error = saturation.calcErrorL1(); saturation.update(); /* */ // just to avoid go out of boundary conditions. for(int j = 0; j <= (ej+1); ++j) for(int i = 0; i <= (ei+0); ++i) { if ( Sw(i,j) > Sw_in) Sw(i,j) = Sw_in; if ( Sw(i,j) <= 0 ) { Sw(i+1,j) = 0.0; } } saturation.updatePhi(Sw); /* */ if ( !(iteration % frequency) ) { NumUtils::interpolateToNodes(p_n, p); NumUtils::interpolateToNodes(Sw_n, Sw); if (rank == 0) { InOut::writeToFile_DX(p_n, idprint, "./DataBL/00/pres.",dx, dy); InOut::writeToFile_DX(Sw_n, idprint, "./DataBL/00/satu.",dx, dy); } if (rank == 1) { InOut::writeToFile_DX(p_n, idprint, "./DataBL/01/pres.",dx, dy); InOut::writeToFile_DX(Sw_n, idprint, "./DataBL/01/satu.",dx, dy); } if (rank == 2) { InOut::writeToFile_DX(p_n, idprint, "./DataBL/02/pres.",dx, dy); InOut::writeToFile_DX(Sw_n, idprint, "./DataBL/02/satu.",dx, dy); } if (rank == 3) { InOut::writeToFile_DX(p_n, idprint, "./DataBL/03/pres.",dx, dy); InOut::writeToFile_DX(Sw_n, idprint, "./DataBL/03/satu.",dx, dy); } std::cout << "\n\n ---- ID print => " << idprint << "\t - Iteration => " << iteration << "\t Step = " << t << "\n ---- Res = " << residual << "\t Err = " << error; //std::cout.flush(); ++idprint; } /* */ subdom.infoExchange1(p); pressure.updatePhi(p); subdom.infoExchange1(Sw); saturation.updatePhi(Sw); /* */ // just to avoid go out of boundary conditions. for(int j = 0; j <= (ej+1); ++j) for(int i = 0; i <= (ei+0); ++i) { if ( Sw(i,j) > Sw_in) Sw(i,j) = Sw_in; if ( Sw(i,j) <= 0 ) { Sw(i+1,j) = 0.0; } } saturation.updatePhi(Sw); /* */ ++iteration; t += dt; } cout << "\n Pres Etime = " << pres_time << " segs \n"; cout << "\n Sat Etime = " << sat_time << " segs \n"; /* **/ MPI::Finalize(); return 0; }