-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimulator.cpp
More file actions
55 lines (44 loc) · 1.93 KB
/
Simulator.cpp
File metadata and controls
55 lines (44 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) Conni Bilham & Lucy Coward 2022, All Rights Reserved.
#include "Simulator.h"
void Simulator::generateWorkQueue() {
auto left_over = star_list->size() % thread_count;
auto overflowList = new std::vector<Star*>();
// Remove the overflowing stars from the star_list and place them in a temp array
// This should never have more than thread_count stars within it
for(int index = 0; index < left_over; ++index) {
overflowList->emplace_back(star_list->at(0));
star_list->erase(star_list->begin());
}
// Populate the work queue with the stars
work_queue->clear();
for(int thread_queue_index = 0; thread_queue_index < thread_count; ++thread_queue_index) {
work_queue->emplace_back(*star_list);
for (int star_index = 0; star_index < star_per_thread; ++star_index) {
int final_star_index = thread_queue_index * star_per_thread + star_index;
work_queue->at(thread_queue_index).emplace_back(star_list->at(final_star_index));
}
}
// Add the overflow stars to the work queue
for(int index = 0; index < left_over; ++index) {
work_queue->at(0).emplace_back(overflowList->at(index));
}
// Add the overflow stars back to the main star_list
for(int index = 0; index < left_over; ++index) {
star_list->emplace_back(overflowList->at(index));
}
}
void multithreadedWorkHandler() {
}
void singlethreadedWorkHandler() {
}
void Simulator::output_info() {
logging::info("---------------------------");
logging::info("Thread count: ", std::to_string(thread_count));
logging::info("Star count: ", star_list->size());
logging::info("Stars per thread: ", std::to_string(star_per_thread));
if(left_over > 0) {
logging::info("--- Moving left over stars into thread 0 ---");
logging::info("Left over stars: ", std::to_string(left_over));
}
logging::info("---------------------------");
}