Skip to content

Commit 8777904

Browse files
committed
throughput stats
1 parent d04266e commit 8777904

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

src/testFmqMemory.cxx

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <stdio.h>
22
#include <unistd.h>
33
#include <string.h>
4+
#include <chrono>
45

56
#include <fairmq/FairMQDevice.h>
67
#include <fairmq/FairMQTransportFactory.h>
@@ -34,19 +35,43 @@ int main(int argc, const char* argv[]) {
3435

3536
printf("Get unmanaged memory\n");
3637
long long mMemorySize = ngb GB;
37-
memoryBuffer = sendingChannel->Transport()->CreateUnmanagedRegion(mMemorySize, [](void* /*data*/, size_t /*size*/, void* /*hint*/) {});
38+
auto t00 = std::chrono::steady_clock::now();
39+
try {
40+
// memoryBuffer = sendingChannel->Transport()->CreateUnmanagedRegion(mMemorySize, [](void* /*data*/, size_t /*size*/, void* /*hint*/) {});
41+
memoryBuffer = sendingChannel->Transport()->CreateUnmanagedRegion(mMemorySize, [](void* /*data*/, size_t /*size*/, void* /*hint*/) {},
42+
"",0,fair::mq::RegionConfig{true, false}); // lock / zero
43+
}
44+
catch(...) {
45+
printf("Failed to get buffer (exception)\n"); return 1;
46+
}
3847
if (memoryBuffer==nullptr) { printf("Failed to get buffer\n"); return 1; }
39-
printf("Got %p : %llu\n", memoryBuffer->GetData(), (unsigned long long)memoryBuffer->GetSize());
48+
memoryBuffer->SetLinger(1);
49+
std::chrono::duration<double> tdiff0 = std::chrono::steady_clock::now() - t00;
50+
printf("Got %p : %llu - %.2lf GB/s\n", memoryBuffer->GetData(), (unsigned long long)memoryBuffer->GetSize(), ngb * 1.0/tdiff0.count());
4051
WAITHERE;
4152

42-
printf("Write to memory\n");
53+
printf("Write to memory, by chunks of 1GB\n");
4354
for (unsigned int i=0; i<ngb; i++) {
55+
auto t0 = std::chrono::steady_clock::now();
4456
char *ptr=(char *)memoryBuffer->GetData();
4557
ptr=&ptr[i GB];
46-
printf("#%u : writing @%p\n",i+1, ptr);
47-
memset(ptr,0,1 GB);
58+
printf("#%u : writing @%p ... ",i+1, ptr);
59+
//memset(ptr,0,1 GB);
60+
//bzero(ptr,1 GB);
61+
// marginally faster to write one byte per memory page
62+
if (1) {
63+
for(size_t j=0; j<1 GB; j += getpagesize()) {
64+
ptr[j]=0;
65+
}
66+
}
67+
std::chrono::duration<double> tdiff = std::chrono::steady_clock::now() - t0;
68+
printf(" %.2lf GB/s\n", 1.0/tdiff.count());
4869
}
4970
printf("Done writing\n");
71+
72+
tdiff0 = std::chrono::steady_clock::now() - t00;
73+
printf("Average: %.2lf GB/s (including alloc)\n", ngb * 1.0/(tdiff0.count()-SLEEPTIME));
74+
5075
WAITHERE;
5176

5277
printf("Cleanup FMQ unmanaged region\n");

0 commit comments

Comments
 (0)