-
Notifications
You must be signed in to change notification settings - Fork 0
/
call_buffer_timer.cpp
167 lines (119 loc) · 5.23 KB
/
call_buffer_timer.cpp
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
Copyright (c) 2024, Hammurabi Mendes.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <iostream>
#include <unistd.h>
#include <vector>
#include <array>
#include <thread>
#include <mutex>
#include "seriema.h"
#include "utils/TimeHolder.hpp"
using std::vector;
using std::array;
using std::thread;
using std::recursive_mutex;
using std::cout;
using std::cerr;
using std::endl;
using seriema::GlobalAddress;
using seriema::number_processes;
using seriema::process_rank;
using seriema::number_threads;
using seriema::thread_rank;
using seriema::number_threads_process;
using seriema::thread_id;
using seriema::context;
using seriema::queue_pairs;
using seriema::incoming_message_queues;
using seriema::Configuration;
constexpr uint64_t number_operations = 65536;
atomic<uint64_t> aggregate_nanosecond_difference[128];
void tester_thread(int offset) {
seriema::init_thread(offset);
atomic<bool> finished = false;
thread *work_queue_consumer = seriema::get_work_queue_consumer(offset, finished, incoming_message_queues[thread_rank]);
TimeHolder timer;
RDMAMemory *source = new RDMAMemory(context, 4096);
uint64_t received = 0;
for(uint64_t iteration = 0; iteration < number_operations; iteration++) {
// if(iteration % 1000 == 0) {
// seriema::print_mutex.lock();
// cout << "ID = " << thread_id << " iteration = " << iteration << " received = " << received << endl;
// seriema::print_mutex.unlock();
// }
int destination_thread_id = iteration % number_threads;
seriema::call_buffer(destination_thread_id, [iteration](void *data, uint64_t size) {
if(iteration % 1000 == 0) {
seriema::print_mutex.lock();
cout << "receiver working on iteration " << iteration << endl;
seriema::print_mutex.unlock();
}
}, source, 0, 4096);
}
seriema::call(thread_id, [&finished] {
finished = true;
});
while(!finished) {
}
long nanosecond_difference = timer.tick();
work_queue_consumer->join();
double message_rate = ((double) (number_operations * 1000000000ULL)) / nanosecond_difference;
double bandwidth = ((double) (number_operations * 4096)) / (1024 * 1024) / (((double) nanosecond_difference) / 1000000000ULL);
seriema::print_mutex.lock();
printf("Rate: %.2f messages/s\nBandwidth: %.2f MB/s\n", message_rate, bandwidth);
seriema::print_mutex.unlock();
aggregate_nanosecond_difference[thread_rank] = nanosecond_difference;
seriema::print_mutex.lock();
cout << "done" << endl;
seriema::print_mutex.unlock();
delete work_queue_consumer;
seriema::finalize_thread();
}
int main(int argc, char **argv) {
vector<thread> thread_list;
if(argc != 2) {
cerr << "Run with format " << argv[0] << " <number_threads_process>" << endl;
exit(EXIT_FAILURE);
}
number_threads_process = atoi(argv[1]);
Configuration configuration{number_threads_process};
seriema::init_thread_handler(argc, argv, configuration);
for(int i = 0; i < number_threads_process; i++) {
thread_list.push_back(thread(tester_thread, i));
}
for(int i = 0; i < number_threads_process; i++) {
thread_list[i].join();
}
long nanosecond_difference = 0;
for(auto i = 0; i < number_threads_process; i++) {
nanosecond_difference += aggregate_nanosecond_difference[i];
}
nanosecond_difference /= number_threads_process;
double message_rate = ((double) (number_operations * 1000000000ULL)) / nanosecond_difference;
double bandwidth = ((double) (number_operations * 4096)) / (1024 * 1024) / (((double) nanosecond_difference) / 1000000000ULL);
printf("AVG Rate: %.2f messages/s\nAVG Bandwidth: %.2f MB/s\n", message_rate, bandwidth);
seriema::finalize_thread_handler();
return 0;
}