// do all the work on 'nx' data points for 'nt' time steps space do_work(std::size_t nx, std::size_t nt) { // U[t][i] is the state of position i at time t. std::vector<space> U(2); for (space& s : U) s.resize(nx); // Initial conditions: f(0, i) = i for (std::size_t i = 0; i != nx; ++i) U[0][i] = double(i); // Actual time step loop for (std::size_t t = 0; t != nt; ++t) { space const& current = U[t % 2]; space& next = U[(t + 1) % 2]; next[0] = heat(current[nx-1], current[0], current[1]); for (std::size_t i = 1; i != nx-1; ++i) next[i] = heat(current[i-1], current[i], current[i+1]); next[nx-1] = heat(current[nx-2], current[nx-1], current[0]); } // Return the solution at time-step 'nt'. return U[nt % 2]; }
// do all the work on 'nx' data points for 'nt' time steps space do_work(std::size_t nx, std::size_t nt) { // U[t][i] is the state of position i at time t. std::vector<space> U(2); for (space& s : U) s.resize(nx); // Initial conditions: f(0, i) = i for (std::size_t i = 0; i != nx; ++i) U[0][i] = double(i); // Actual time step loop for (std::size_t t = 0; t != nt; ++t) { space const& current = U[t % 2]; space& next = U[(t + 1) % 2]; next[0] = heat(current[nx-1], current[0], current[1]); // Visual Studio requires OMP loop variables to be signed :/ # pragma omp parallel for for (boost::int64_t i = 1; i < boost::int64_t(nx-1); ++i) next[i] = heat(current[i-1], current[i], current[i+1]); next[nx-1] = heat(current[nx-2], current[nx-1], current[0]); } // Return the solution at time-step 'nt'. return U[nt % 2]; }
void SCKAmbient::getMICS(){ // Charging tension heaters heat(MICS_5525, 32); //Corriente en mA heat(MICS_2710, 26); //Corriente en mA RsCO = readMICS(MICS_5525); RsNO2 = readMICS(MICS_2710); }
// The partitioned operator, it invokes the heat operator above on all // elements of a partition. static partition_data heat_part(partition_data const& left, partition_data const& middle, partition_data const& right) { std::size_t size = middle.size(); partition_data next(size); next[0] = heat(left[size-1], middle[0], middle[1]); for (std::size_t i = 1; i != size-1; ++i) next[i] = heat(middle[i-1], middle[i], middle[i+1]); next[size-1] = heat(middle[size-2], middle[size-1], right[0]); return next; }
// The partitioned operator, it invokes the heat operator above on all // elements of a partition. static partition_data heat_part(partition_data const& left, partition_data const& middle, partition_data const& right) { std::size_t size = middle.size(); partition_data next(size); next[0] = heat(left[size-1], middle[0], middle[1]); // Visual Studio requires OMP loop variables to be signed :/ # pragma omp parallel for for (boost::int64_t i = 1; i < boost::int64_t(size-1); ++i) next[i] = heat(middle[i-1], middle[i], middle[i+1]); next[size-1] = heat(middle[size-2], middle[size-1], right[0]); return next; }
/*---------------------------------------------------------------------------*\ | SixStepTemplateMethod template method \*---------------------------------------------------------------------------*/ void SixStepTemplateMethod::template_method() { setup(); schedule(); heat(); optimize(); cleanup(); putaway(); }
void mc() { init_dihs(); LOG << "Start MC...\n" << "Energy: " << total_dist_energy(c) << "(dist) " << total_dih_energy() << "(dih)\n" << "Temprature: " << _mc_tempr << std::endl; heat(); cool(); LOG << "Finish MC.\nDistance energy: " << total_dist_energy(c) << " Chirality energy: " << total_dih_energy() << '\n'; }
// Here we go.. int main() { // Initialize the OpTiMSoC library optimsoc_init(0); optimsoc_mp_simple_init(); // Add a handler for class 0 packets to the mpsimple message passing // driver. The driver will execute recv (see definition above) each // time a packet arrives. optimsoc_mp_simple_addhandler(0,&recv); or1k_interrupts_enable(); // Determine my rank and total number rank = optimsoc_ctrank(); total = optimsoc_ctnum(); // Determine number of rows and columns xcount = workshare[total-1][0]; ycount = workshare[total-1][1]; // Define tracing optimsoc_trace_definesection(0,"initialization"); optimsoc_trace_definesection(1,"compute"); optimsoc_trace_definesection(2,"update"); optimsoc_trace_definesection(3,"barrier"); optimsoc_trace_section(0); // If this rank is not part of the grid, just quit.. if (rank >= xcount*ycount) return -1; // Determine this ranks column and row col = rank % xcount; for(row=0;(row+1)*xcount<=rank;row++) {} // Determine whether this rank is on one of the boundaries leftbound = (col==0); rightbound = (col==xcount-1); topbound = (row==0); bottombound = (row==ycount-1); // The default for xdim and ydim is simple but rounded xdim = (XSIZE/xcount); ydim = (YSIZE/ycount); // The base address is easily calculated based on this xbase = xdim * col; ybase = ydim * row; // And the last in a row and in a column need to get their // dimensions adjusted to match the rounding if (rightbound) xdim = XSIZE - xdim*(xcount-1); if (bottombound) ydim = YSIZE - ydim*(ycount-1); // We start with matrix 0 as initial value and matrix 1 // for the first calculation curmatrix = 1; // Inititalize sufficient memory (remember extra rows and cols) matrix[0] = malloc(sizeof(float)*(xdim+2)*(ydim+2)); matrix[1] = malloc(sizeof(float)*(xdim+2)*(ydim+2)); // Initialize all with zeros for (int x=0;x<xdim+2;x++) { for (int y=0;y<ydim+2;y++) { matrix[0][POS(x,y)] = 0; matrix[1][POS(x,y)] = 0; } } // To see any heat distribution we need a hot spot, that // is here on the upper left corner. if (rank==0) { matrix[0][POS(0,0)] = 9.99; matrix[0][POS(1,0)] = 9.99; matrix[0][POS(0,1)] = 9.99; matrix[0][POS(0,2)] = 9.99; matrix[1][POS(0,0)] = 9.99; matrix[1][POS(1,0)] = 9.99; matrix[1][POS(0,1)] = 9.99; matrix[1][POS(0,2)] = 9.99; } // Allocate memory for the result matrix if (rank==0) { result = malloc(XSIZE*YSIZE*sizeof(float)); } // Call the heat function that does all processing heat(); // Print results after all iterations from core 0 if (rank==0) { for (int y=0;y<YSIZE;y++) { for (int x=0;x<XSIZE;x++) { printf("%.2f ",result[x+y*XSIZE]); } printf("\n"); } } return 0; }
void HeatSimulator::run_(Module::Slot slot) { const auto totalSlots = owner_.totalSlots_(slot); auto modules = owner_.modules_(slot); modules.erase(std::remove_if(modules.begin(), modules.end(), [totalSlots](auto i) { return i->socket_() >= totalSlots; }), modules.end()); if (modules.empty()) return; const auto onlineModules = std::count_if(modules.begin(), modules.end(), [](auto i) { return i->state_() >= Module::State::online; }); const auto heatAbsorbtionRateModifier = std::accumulate(modules.begin(), modules.end(), Float(0), [](auto sum, auto i) { return i->state_() == Module::State::overloaded ? sum + i->attribute_(AttributeID::heatAbsorbtionRateModifier)->value_() : sum; }); const auto heatGeneration = heatAbsorbtionRateModifier * heatGenerationMultiplier_; Float heatCapacity = 0; Float heatAttenuation = 0; switch (slot) { case Module::Slot::hi: heatCapacity = owner_.attribute_(AttributeID::heatCapacityHi)->value_() / 100.0; heatAttenuation = owner_.attribute_(AttributeID::heatAttenuationHi)->value_(); break; case Module::Slot::med: heatCapacity = owner_.attribute_(AttributeID::heatCapacityMed)->value_() / 100.0; heatAttenuation = owner_.attribute_(AttributeID::heatAttenuationMed)->value_(); break; case Module::Slot::low: heatCapacity = owner_.attribute_(AttributeID::heatCapacityLow)->value_() / 100.0; heatAttenuation = owner_.attribute_(AttributeID::heatAttenuationLow)->value_(); break; default: break; } std::vector<std::pair<HP, Module*>> hp(totalSlots, std::make_pair(HP(0), nullptr)); std::vector<State> c; c.reserve(modules.size()); for (auto i: modules) { hp[i->socket_()] = std::make_pair(i->attribute_(AttributeID::hp)->value_(), i); if (i->state_() == Module::State::overloaded) { c.emplace_back(i->rawCycleTime_(), i->reloadTime_(), i->attribute_(AttributeID::heatDamage)->value_(), i->shots_(), i->socket_()); } } if (c.empty()) return; typedef std::priority_queue<State, std::vector<State>, std::greater<>> PQ; PQ states(PQ::value_compare(), std::move(c)); auto tNow = 0ms; while (true) { auto state = states.top(); states.pop(); tNow = state.tNow; auto h = heat(tNow, heatCapacity, heatGeneration); std::size_t dead = 0; for (int i = 0; i < totalSlots; i++) { if (hp[i].first > 0) { auto range = std::abs(i - static_cast<int>(state.socket)); hp[i].first -= damageProbability(h, range, onlineModules, totalSlots, heatAttenuation) * state.heatDamage; if (hp[i].first <= 0) { hp[i].second->lifeTime_ (tNow); dead++; } } else dead++; } if (dead >= totalSlots) break; tNow += state.cycleTime; state.shot++; if (state.clipSize > 0) { if (state.shot % state.clipSize == 0) { state.shot = 0; tNow += state.reloadTime; } } state.tNow = tNow; states.push(state); } }
void create_constant_scalar_field(CMesh& mesh, const std::string& field_name, const std::string& var_name, const Real value) { MeshTerm<1, ScalarField> heat(field_name, var_name); mesh.create_scalar_field(field_name, var_name, CField::Basis::POINT_BASED); for_each_node(mesh.topology(), heat = value); }
void random_generator::reinit(const int & seed) { srand(seed); heat(); }
void random_generator::reinit() { srand(time(0)); heat(); }