123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- /**
- * @file tests/multithreading/lifegame/main.cpp
- * @author The ARTIS Development Team
- * See the AUTHORS or Authors.txt file
- */
- /*
- * ARTIS - the multimodeling and simulation environment
- * This file is a part of the ARTIS environment
- *
- * Copyright (C) 2013-2019 ULCO http://www.univ-littoral.fr
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #include <artis-star/common/RootCoordinator.hpp>
- #include <tests/multithreading/lifegame/graph_manager.hpp>
- #include <tests/multithreading/lifegame/models.hpp>
- #include <chrono>
- using namespace artis::common;
- using namespace std::chrono;
- using namespace artis::tests::multithreading::lifegame;
- class View : public artis::observer::View<artis::common::DoubleTime> {
- public:
- View()
- {
- selector("Cell:state", {FlatGraphManager::CELL, ALL, Cell::STATE});
- }
- };
- void show_state(const GridGraphManagerParameters& graph_parameters,
- const artis::observer::View<artis::common::DoubleTime>& view)
- {
- std::vector<std::vector<std::vector<bool> > > states;
- for (unsigned int t = 0; t <= 11; ++t) {
- states.emplace_back(std::vector<std::vector<bool> >());
- for (unsigned int i = 0; i < graph_parameters.column_number; ++i) {
- states[t].emplace_back(std::vector<bool>());
- for (unsigned int j = 0; j < graph_parameters.line_number; ++j) {
- states[t][i].emplace_back(false);
- }
- }
- }
- for (unsigned int i = 0; i < graph_parameters.column_number; ++i) {
- for (unsigned int j = 0; j < graph_parameters.line_number; ++j) {
- std::ostringstream ss;
- ss << ":root:C_" << (i + 1) << "_" << (j + 1) << ":state";
- const ::View::Values& values = view.get("Cell:state", ss.str());
- for (const auto& value: values) {
- bool state;
- value.second(state);
- states[(int)value.first][i][j] = state;
- }
- }
- }
- for (unsigned int t = 0; t <= 10; ++t) {
- for (unsigned int i = 0; i < graph_parameters.column_number; ++i) {
- for (unsigned int j = 0; j < graph_parameters.line_number; ++j) {
- std::cout << states[t][i][j] << " ";
- }
- std::cout << std::endl;
- }
- std::cout << std::endl;
- }
- }
- double lifegame_monothreading()
- {
- CellParameters parameters({
- {
- {"C_1_1", 2},
- {"C_1_2", 3},
- {"C_1_3", 3},
- {"C_1_4", 3},
- {"C_1_5", 2},
- {"C_2_1", 3},
- {"C_2_2", 4},
- {"C_2_3", 4},
- {"C_2_4", 4},
- {"C_2_5", 3},
- {"C_3_1", 3},
- {"C_3_2", 4},
- {"C_3_3", 4},
- {"C_3_4", 4},
- {"C_3_5", 3},
- {"C_4_1", 3},
- {"C_4_2", 4},
- {"C_4_3", 4},
- {"C_4_4", 4},
- {"C_4_5", 3},
- {"C_5_1", 2},
- {"C_5_2", 3},
- {"C_5_3", 3},
- {"C_5_4", 3},
- {"C_5_5", 2},
- },
- {
- {"C_1_1", false},
- {"C_1_2", false},
- {"C_1_3", false},
- {"C_1_4", false},
- {"C_1_5", false},
- {"C_2_1", false},
- {"C_2_2", false},
- {"C_2_3", true},
- {"C_2_4", false},
- {"C_2_5", false},
- {"C_3_1", false},
- {"C_3_2", false},
- {"C_3_3", true},
- {"C_3_4", false},
- {"C_3_5", false},
- {"C_4_1", false},
- {"C_4_2", false},
- {"C_4_3", true},
- {"C_4_4", false},
- {"C_4_5", false},
- {"C_5_1", false},
- {"C_5_2", false},
- {"C_5_3", false},
- {"C_5_4", false},
- {"C_5_5", false},
- }
- });
- GridGraphManagerParameters graph_parameters({5, 5});
- artis::common::RootCoordinator<
- DoubleTime, artis::pdevs::Coordinator<
- DoubleTime,
- FlatGraphManager,
- CellParameters,
- GridGraphManagerParameters>
- > rc(0, 10, "root", parameters, graph_parameters);
- rc.attachView("Matrix", new ::View());
- steady_clock::time_point t1 = steady_clock::now();
- rc.run();
- steady_clock::time_point t2 = steady_clock::now();
- duration<double> time_span = duration_cast<duration<double> >(t2 - t1);
- show_state(graph_parameters, rc.observer().view("Matrix"));
- return time_span.count();
- }
- double lifegame_multithreading()
- {
- // artis::common::RootCoordinator<
- // DoubleTime, artis::pdevs::multithreading::Coordinator<
- // DoubleTime,
- // ParallelHierarchicalGraphManager,
- // artis::common::NoParameters,
- // GraphManagerParameters>
- // > rc(0, 10, "root", artis::common::NoParameters(), GraphManagerParameters(cluster_number));
- steady_clock::time_point t1 = steady_clock::now();
- // rc.run();
- steady_clock::time_point t2 = steady_clock::now();
- duration<double> time_span = duration_cast<duration<double> >(t2 - t1);
- return time_span.count();
- }
- int main()
- {
- std::cout << lifegame_monothreading() << std::endl;
- std::cout << lifegame_multithreading() << std::endl;
- return 0;
- }
|