void thread_pool::main_loop() { while (is_running_) { boost::unique_lock<boost::mutex> locker(lock_); while (tasks_.empty() && is_running_) { queue_check_.wait(locker); } if (stop_condition()) { queue_check_.notify_all(); break; } { boost::function<void()> task = tasks_.front(); tasks_.pop(); --available_; locker.unlock(); task(); } locker.lock(); ++available_; } }
QAP_solution_t *aco(QAP_t *prob){ int i; QAP_solution_t *sol; ant_system_init(prob); for (i = 0; !stop_condition(prob, i); i++) { ant_construct_solutions(prob); aco_local_search(prob); aco_update_pheromones(prob); if (prob->flags & VERBOSE){ printf("\nGeneration %d -- Best Cost %d\n\n", i, best_solution->cst); } else { printf("."); fflush(stdout); } } if (found_artificial_value) best_solution->time = current_user_time_secs(); //QAP_check_solution(prob, best_solution); sol = Malloc(sizeof(QAP_solution_t)); *sol = *best_solution; sol->geration = i; return sol; }
void IterativeSolver::execute() { RDM::RDSolver& mysolver = *solver().handle< RDM::RDSolver >(); /// @todo this configuration sould be in constructor but does not work there configure_option_recursively( "iterator", handle<Component>() ); // access components (out of loop) ActionDirector& boundary_conditions = *access_component( "cpath:../BoundaryConditions" )->handle<ActionDirector>(); ActionDirector& domain_discretization = *access_component( "cpath:../DomainDiscretization" )->handle<ActionDirector>(); Action& synchronize = *mysolver.actions().get_child("Synchronize")->handle<Action>(); Handle<Component> cnorm = post_actions().get_child("ComputeNorm"); cnorm->options().set("table", follow_link(mysolver.fields().get_child( RDM::Tags::residual() ))->uri() ); Component& cprint = *post_actions().get_child("IterationSummary"); cprint.options().set("norm", cnorm ); // iteration loop Uint iter = 1; // iterations start from 1 ( max iter zero will do nothing ) properties().property("iteration") = iter; while( ! stop_condition() ) // non-linear loop { // (1) the pre actions - cleanup residual, pre-process something, etc pre_actions().execute(); // (2) domain discretization domain_discretization.execute(); // (3) apply boundary conditions boundary_conditions.execute(); // (4) update update().execute(); // (5) update synchronize.execute(); // (6) the post actions - compute norm, post-process something, etc post_actions().execute(); // raise signal that iteration is done raise_iteration_done(); // increment iteration properties().property("iteration") = ++iter; // update the iteration number } }
int main(void) { set_ddr(WRITE); // Pull-Ups aus PORTB = 0x00; start_condition(); address_7_write(0x40); lcd_init(); lcd_write(ZEILE_1, 0, "HS-Fulda"); lcd_write(ZEILE_2, 0, "Hallo Welt"); stop_condition(); return 0; }
int main(int argc, char *argv[]) { // Need to change to 3. need to remove the logging. if (argc != 4) { printf("Usage: ./maxcut <input data path> <output data path> <log file>\n"); exit(-1); } // Need to remove when submitting. log_file = fopen(argv[3], "w"); fprintf(log_file, "rate, elasped time (s), max val, avg val\n"); start_time = get_seconds(); in = fopen(argv[1], "r"); out = fopen(argv[2], "w"); int i, j, v1, v2, w; // (v1, v2) is the vertex and w is the weight fscanf(in, "%d %d\n", &num_of_vertex, &num_of_edge); int edge[num_of_vertex+1][num_of_vertex+1]; for (i=0; i<=SIZE; i++) for (j=0; j<=SIZE; j++) edge[i][j] = 0; while (fscanf(in, "%d %d %d\n", &v1, &v2, &w) != EOF) { edge[v1][v2] = w; edge[v2][v1] = w; } init_population(); init_offsprings(); init_cost(edge); sort_population(); init_crossover(); int p1, p2; while (!(stop_condition())) { generation++; for (i=1; i<=K; i++) { selection(&p1, &p2); crossover(i, p1, p2); mutation(i); local_optimization(i, edge); } replacement(edge); sort_population(); } for (i=1; i<=SIZE; i++) { if (population[N]->ch[i] == 1) fprintf(out, "%d ", i); } free_population(); fclose(in); fclose(out); printf("N: %d, K: %d, S_RATE: %lf, M_THRE: %lf, P0: %lf, POINTS: %d, K_FIT: %d, T: %lf\n", N, K, S_RATE, M_THRE, P0, POINTS, K_FIT, T); return 0; }
void IterativeSolver::execute() { RDM::RDSolver& mysolver = solver().as_type< RDM::RDSolver >(); /// @todo this configuration sould be in constructor but does not work there configure_option_recursively( "iterator", this->uri() ); // access components (out of loop) CActionDirector& boundary_conditions = access_component( "cpath:../BoundaryConditions" ).as_type<CActionDirector>(); CActionDirector& domain_discretization = access_component( "cpath:../DomainDiscretization" ).as_type<CActionDirector>(); CAction& synchronize = mysolver.actions().get_child("Synchronize").as_type<CAction>(); Component& cnorm = post_actions().get_child("ComputeNorm"); cnorm.configure_option("Field", mysolver.fields().get_child( RDM::Tags::residual() ).follow()->uri() ); // iteration loop Uint iter = 1; // iterations start from 1 ( max iter zero will do nothing ) property("iteration") = iter; while( ! stop_condition() ) // non-linear loop { // (1) the pre actions - cleanup residual, pre-process something, etc pre_actions().execute(); // (2) domain discretization domain_discretization.execute(); // (3) apply boundary conditions boundary_conditions.execute(); // (4) update update().execute(); // (5) update synchronize.execute(); // (6) the post actions - compute norm, post-process something, etc post_actions().execute(); // output convergence info /// @todo move current rhs as a prpoerty of the iterate or solver components if( Comm::PE::instance().rank() == 0 ) { Real rhs_norm = cnorm.properties().value<Real>("Norm"); CFinfo << "iter [" << std::setw(4) << iter << "]" << "L2(rhs) [" << std::setw(12) << rhs_norm << "]" << CFendl; if ( is_nan(rhs_norm) || is_inf(rhs_norm) ) throw FailedToConverge(FromHere(), "Solution diverged after "+to_str(iter)+" iterations"); } // raise signal that iteration is done raise_iteration_done(); // increment iteration property("iteration") = ++iter; // update the iteration number } }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { CORBA::ORB_var orb_; int result = 0; try { ACE_DEBUG((LM_INFO,"(%P|%t) START OF SERVER TEST\n")); orb_ = CORBA::ORB_init (argc, argv, "myorb-server"); if (parse_args (argc, argv) != 0) return 1; CORBA::Object_var poa_object = orb_->resolve_initial_references("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); PortableServer::POA_var poa = root_poa; poa_manager->activate (); ACE_DEBUG((LM_INFO,"(%P|%t) ORB initialized\n")); // Creating the servant and activating it // Test_Idl_SharedIntf_i* intf_i = new Test_Idl_SharedIntf_i(orb_.in()); PortableServer::ServantBase_var base_var = intf_i; PortableServer::ObjectId_var intfId_var = poa->activate_object(base_var.in()); CORBA::Object_var obj_var = poa->id_to_reference(intfId_var.in()); Test_Idl::SharedIntf_var intf_var = Test_Idl::SharedIntf::_narrow(obj_var.in()); // Creating stringified IOR of the servant and writing it to a file. // CORBA::String_var intfString_var = orb_->object_to_string(intf_var.in()); // Output the IOR to the <ior_output_file> FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: %s\n", ior_output_file), 1); ACE_OS::fprintf (output_file, "%s", intfString_var.in ()); ACE_OS::fclose (output_file); ACE_DEBUG((LM_INFO,"(%P|%t) server IOR to %s\n", ior_output_file)); // Running ORB in separate thread Worker worker (orb_.in ()); if (worker.activate (THR_NEW_LWP | THR_JOINABLE, nr_threads) != 0) ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p\n", "Cannot activate server thread(s)"), -1); ACE_DEBUG((LM_INFO,"(%P|%t) Await client initialization\n")); poll ("./client.ior"); ACE_DEBUG((LM_INFO,"(%P|%t) Client IOR file was detected\n")); ACE_Mutex mutex; ACE_Condition<ACE_Mutex> stop_condition (mutex); { ACE_GUARD_RETURN (ACE_Mutex, guard, mutex, -1); Chatter worker2 (orb_.in (), ACE_TEXT("file://client.ior"), stop_condition); if (worker2.activate (THR_NEW_LWP | THR_JOINABLE, 1) != 0) { ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p\n", "Cannot activate chatty client threads"), -1); } do { stop_condition.wait (); ACE_DEBUG((LM_INFO,"(%P|%t) So far, %d/%d requests/replies have been processed\n", worker2.nrequests (), worker2.nreplies ())); } while (worker2.nrequests () < 1); worker.thr_mgr()->wait (); root_poa->destroy(1, 1); orb_->destroy(); ACE_DEBUG((LM_INFO,"(%P|%t) Server Test %C\n", (worker2.nrequests() == worker2.nreplies())?"succeeded":"failed")); result = (worker2.nrequests() == worker2.nreplies())? 0 : -1; } } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Error: Exception caught:"); } ACE_OS::unlink ("server.ior"); return result; }