|
1 | 1 | #include <stdio.h> |
2 | 2 | #include <unistd.h> |
3 | 3 | #include <string.h> |
| 4 | +#include <chrono> |
4 | 5 |
|
5 | 6 | #include <fairmq/FairMQDevice.h> |
6 | 7 | #include <fairmq/FairMQTransportFactory.h> |
@@ -34,19 +35,43 @@ int main(int argc, const char* argv[]) { |
34 | 35 |
|
35 | 36 | printf("Get unmanaged memory\n"); |
36 | 37 | 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 | + } |
38 | 47 | 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()); |
40 | 51 | WAITHERE; |
41 | 52 |
|
42 | | - printf("Write to memory\n"); |
| 53 | + printf("Write to memory, by chunks of 1GB\n"); |
43 | 54 | for (unsigned int i=0; i<ngb; i++) { |
| 55 | + auto t0 = std::chrono::steady_clock::now(); |
44 | 56 | char *ptr=(char *)memoryBuffer->GetData(); |
45 | 57 | 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()); |
48 | 69 | } |
49 | 70 | 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 | + |
50 | 75 | WAITHERE; |
51 | 76 |
|
52 | 77 | printf("Cleanup FMQ unmanaged region\n"); |
|
0 commit comments