Skip to content

Commit

Permalink
Apply clang-format on repository
Browse files Browse the repository at this point in the history
  • Loading branch information
aobolensk committed Dec 30, 2023
1 parent b343699 commit e9b9696
Show file tree
Hide file tree
Showing 42 changed files with 2,758 additions and 2,514 deletions.
4 changes: 2 additions & 2 deletions 3rdparty/unapproved/unapproved.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#include <thread>
#include <future>
#include <chrono>
#include <future>
#include <thread>
29 changes: 15 additions & 14 deletions first_samples/mpi/main.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
// Copyright 2023 Nesterov Alexander
#include <mpi.h>

#include <iostream>

int main(int argc, char** argv) {
MPI_Init(&argc, &argv);
MPI_Init(&argc, &argv);

int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);

int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);

char processor_name[MPI_MAX_PROCESSOR_NAME];
int len_chars;
MPI_Get_processor_name(processor_name, &len_chars);
char processor_name[MPI_MAX_PROCESSOR_NAME];
int len_chars;
MPI_Get_processor_name(processor_name, &len_chars);

MPI_Barrier(MPI_COMM_WORLD);
std::cout << "Processor = " << processor_name << std::endl;
std::cout << "Rank = " << world_rank << std::endl;
std::cout << "Number of processors = " << world_size << std::endl;
MPI_Barrier(MPI_COMM_WORLD);
std::cout << "Processor = " << processor_name << std::endl;
std::cout << "Rank = " << world_rank << std::endl;
std::cout << "Number of processors = " << world_size << std::endl;

MPI_Finalize();
return 0;
MPI_Finalize();
return 0;
}
22 changes: 12 additions & 10 deletions first_samples/mpi_boost/main.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
// Copyright 2023 Nesterov Alexander
#include <mpi.h>
#include <string>
#include <iostream>
#include <boost/mpi/environment.hpp>

#include <boost/mpi/communicator.hpp>
#include <boost/mpi/environment.hpp>
#include <iostream>
#include <string>

// https://www.boost.org/doc/libs/1_68_0/doc/html/mpi/tutorial.html
int main(int argc, char** argv) {
boost::mpi::environment env(argc, argv);
boost::mpi::communicator world;
boost::mpi::environment env(argc, argv);
boost::mpi::communicator world;

world.barrier();
std::cout << "Processor = " << boost::mpi::environment::processor_name() << std::endl;
std::cout << "Rank = " << world.rank() << std::endl;
std::cout << "Number of processors = " << world.size() << std::endl;
world.barrier();
std::cout << "Processor = " << boost::mpi::environment::processor_name()
<< std::endl;
std::cout << "Rank = " << world.rank() << std::endl;
std::cout << "Number of processors = " << world.size() << std::endl;

return 0;
return 0;
}
41 changes: 24 additions & 17 deletions modules/core/include/perf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,45 @@
#define MODULES_CORE_INCLUDE_PERF_HPP_

#include <cstdint>
#include <vector>
#include <memory>
#include <functional>
#include <memory>
#include <vector>

#include "core/include/task.hpp"

namespace ppc {
namespace core {

struct PerfAttr {
// count of task's running
uint64_t num_running;
// count of task's running
uint64_t num_running;
};

struct PerfResults {
// measurement of task's time (in seconds)
long double time_sec;
// measurement of task's time (in seconds)
long double time_sec;
};

class Perf {
public:
// Init performance analysis with initialized task and initialized data
explicit Perf(std::shared_ptr<Task> task_);
// Set task with initialized task and initialized data for performance analysis c
void set_task(std::shared_ptr<Task> task_);
// Check performance of full task's pipeline: pre_processing() -> validation() -> run() -> post_processing()
void pipeline_run(std::shared_ptr<PerfAttr> perfAttr, std::shared_ptr<ppc::core::PerfResults> perfResults);
// Check performance of task's run() function
void task_run(std::shared_ptr<PerfAttr> perfAttr, std::shared_ptr<ppc::core::PerfResults> perfResults);
// Init performance analysis with initialized task and initialized data
explicit Perf(std::shared_ptr<Task> task_);
// Set task with initialized task and initialized data for performance
// analysis c
void set_task(std::shared_ptr<Task> task_);
// Check performance of full task's pipeline: pre_processing() ->
// validation() -> run() -> post_processing()
void pipeline_run(std::shared_ptr<PerfAttr> perfAttr,
std::shared_ptr<ppc::core::PerfResults> perfResults);
// Check performance of task's run() function
void task_run(std::shared_ptr<PerfAttr> perfAttr,
std::shared_ptr<ppc::core::PerfResults> perfResults);

private:
std::shared_ptr<Task> task;
static void common_run(std::shared_ptr<PerfAttr> perfAttr, std::function<void()> pipeline,
std::shared_ptr<ppc::core::PerfResults> perfResults);
std::shared_ptr<Task> task;
static void common_run(std::shared_ptr<PerfAttr> perfAttr,
std::function<void()> pipeline,
std::shared_ptr<ppc::core::PerfResults> perfResults);
};

} // namespace core
Expand Down
53 changes: 27 additions & 26 deletions modules/core/include/task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,54 @@
#define MODULES_CORE_INCLUDE_TASK_HPP_

#include <cstdint>
#include <vector>
#include <memory>
#include <iostream>
#include <memory>
#include <string>
#include <vector>

namespace ppc::core {

struct TaskData {
std::vector<uint8_t *> inputs;
std::vector<std::uint32_t> inputs_count;
std::vector<uint8_t *> outputs;
std::vector<std::uint32_t> outputs_count;
std::vector<uint8_t *> inputs;
std::vector<std::uint32_t> inputs_count;
std::vector<uint8_t *> outputs;
std::vector<std::uint32_t> outputs_count;
};

// Memory of inputs and outputs need to be initialized before create object of Task class
// Memory of inputs and outputs need to be initialized before create object of
// Task class
class Task {
public:
explicit Task(std::shared_ptr<TaskData> taskData_);
explicit Task(std::shared_ptr<TaskData> taskData_);

// set input and output data
void set_data(std::shared_ptr<TaskData> taskData_);
// set input and output data
void set_data(std::shared_ptr<TaskData> taskData_);

// validation of data and validation of task attributes before running
virtual bool validation() = 0;
// validation of data and validation of task attributes before running
virtual bool validation() = 0;

// pre-processing of input data
virtual bool pre_processing() = 0;
// pre-processing of input data
virtual bool pre_processing() = 0;

// realization of current task
virtual bool run() = 0;
// realization of current task
virtual bool run() = 0;

// post-processing of output data
virtual bool post_processing() = 0;
// post-processing of output data
virtual bool post_processing() = 0;

// get input and output data
[[nodiscard]] std::shared_ptr<TaskData> get_data() const;
// get input and output data
[[nodiscard]] std::shared_ptr<TaskData> get_data() const;

~Task();
~Task();

protected:
void internal_order_test(const std::string &str = __builtin_FUNCTION());
std::shared_ptr<TaskData> taskData;
void internal_order_test(const std::string &str = __builtin_FUNCTION());
std::shared_ptr<TaskData> taskData;

private:
std::vector<std::string> functions_order;
std::vector<std::string> right_functions_order =
{"validation", "pre_processing", "run", "post_processing"};
std::vector<std::string> functions_order;
std::vector<std::string> right_functions_order = {
"validation", "pre_processing", "run", "post_processing"};
};

} // namespace ppc::core
Expand Down
58 changes: 33 additions & 25 deletions modules/core/src/perf.cpp
Original file line number Diff line number Diff line change
@@ -1,44 +1,52 @@
// Copyright 2023 Nesterov Alexander
#include <utility>
#include <iostream>
#include "core/include/perf.hpp"

#include <iostream>
#include <utility>

#include "unapproved/unapproved.h"

ppc::core::Perf::Perf(std::shared_ptr<Task> task_) {
set_task(std::move(task_));
set_task(std::move(task_));
}

void ppc::core::Perf::set_task(std::shared_ptr<Task> task_) {
task = std::move(task_);
task = std::move(task_);
}

void ppc::core::Perf::pipeline_run(std::shared_ptr<PerfAttr> perfAttr,
std::shared_ptr<ppc::core::PerfResults> perfResults) {
common_run(std::move(perfAttr), [&]() {
void ppc::core::Perf::pipeline_run(
std::shared_ptr<PerfAttr> perfAttr,
std::shared_ptr<ppc::core::PerfResults> perfResults) {
common_run(
std::move(perfAttr),
[&]() {
task->validation();
task->pre_processing();
task->run();
task->post_processing();
}, std::move(perfResults));
},
std::move(perfResults));
}

void ppc::core::Perf::task_run(std::shared_ptr<PerfAttr> perfAttr,
std::shared_ptr<ppc::core::PerfResults> perfResults) {
task->validation();
task->pre_processing();
common_run(std::move(perfAttr), [&]() {
task->run();
}, std::move(perfResults));
task->post_processing();
void ppc::core::Perf::task_run(
std::shared_ptr<PerfAttr> perfAttr,
std::shared_ptr<ppc::core::PerfResults> perfResults) {
task->validation();
task->pre_processing();
common_run(
std::move(perfAttr), [&]() { task->run(); }, std::move(perfResults));
task->post_processing();
}

void ppc::core::Perf::common_run(std::shared_ptr<PerfAttr> perfAttr, std::function<void()> pipeline,
std::shared_ptr<ppc::core::PerfResults> perfResults) {
auto begin = std::chrono::high_resolution_clock::now();
for (int i = 0; i < perfAttr->num_running; i++) {
pipeline();
}
auto end = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin).count();
perfResults->time_sec = duration * 1e-9;
void ppc::core::Perf::common_run(
std::shared_ptr<PerfAttr> perfAttr, std::function<void()> pipeline,
std::shared_ptr<ppc::core::PerfResults> perfResults) {
auto begin = std::chrono::high_resolution_clock::now();
for (int i = 0; i < perfAttr->num_running; i++) {
pipeline();
}
auto end = std::chrono::high_resolution_clock::now();
auto duration =
std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin).count();
perfResults->time_sec = duration * 1e-9;
}
39 changes: 20 additions & 19 deletions modules/core/src/task.cpp
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
// Copyright 2023 Nesterov Alexander
#include "core/include/task.hpp"
#include <utility>

#include <stdexcept>
#include <utility>

void ppc::core::Task::set_data(std::shared_ptr<TaskData> taskData_) {
functions_order.clear();
taskData = std::move(taskData_);
functions_order.clear();
taskData = std::move(taskData_);
}

std::shared_ptr<ppc::core::TaskData> ppc::core::Task::get_data() const {
return taskData;
return taskData;
}

ppc::core::Task::Task(std::shared_ptr<TaskData> taskData_) {
set_data(std::move(taskData_));
set_data(std::move(taskData_));
}

void ppc::core::Task::internal_order_test(const std::string& str) {
if (!functions_order.empty() && str == functions_order.back() && str == "run")
return;
void ppc::core::Task::internal_order_test(const std::string& str) {
if (!functions_order.empty() && str == functions_order.back() && str == "run")
return;

functions_order.push_back(str);
functions_order.push_back(str);

for (auto i = 0; i < functions_order.size(); i++) {
if (functions_order[i] != right_functions_order[i % right_functions_order.size()]) {
throw std::invalid_argument("ORDER OF FUCTIONS IS NOT RIGHT: \n" +
std::string("Serial number: ") + std::to_string(i + 1) + "\n" +
std::string("Yours function: ") + functions_order[i] + "\n" +
std::string("Expected function: ") + right_functions_order[i]);
}
for (auto i = 0; i < functions_order.size(); i++) {
if (functions_order[i] !=
right_functions_order[i % right_functions_order.size()]) {
throw std::invalid_argument(
"ORDER OF FUCTIONS IS NOT RIGHT: \n" +
std::string("Serial number: ") + std::to_string(i + 1) + "\n" +
std::string("Yours function: ") + functions_order[i] + "\n" +
std::string("Expected function: ") + right_functions_order[i]);
}
}
}

ppc::core::Task::~Task() {
functions_order.clear();
}
ppc::core::Task::~Task() { functions_order.clear(); }
Loading

0 comments on commit e9b9696

Please sign in to comment.