summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp64
1 files changed, 0 insertions, 64 deletions
diff --git a/main.cpp b/main.cpp
deleted file mode 100644
index 0cb47fa..0000000
--- a/main.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-#include <iostream>
-#include <unistd.h>
-#include <sys/mman.h>
-#include <string>
-#include <omp.h>
-
-#define GIG (1024ul*1024*1024)
-#define VOLUME (1024ul*1024*1024)
-
-// Real values is in the ~65536, only use half of it to be safe
-// sysctl vm.max_map_count
-#define MAXMMAPS 32768
-
-int main(int argc, char **argv) {
- auto page_size = sysconf(_SC_PAGESIZE);
- std::cout << "The system have a page size of " << page_size << std::endl;
- // Src is using anonymous mapping
- long nmaps = 1024;
- if (argc > 1) {
- nmaps = std::stoi(argv[1]);
- if (VOLUME / page_size % nmaps != 0) {
- std::cout << "nmaps is not perfect multiple, quit" << std::endl;
- return 0;
- }
- }
-
- long mmap_sz = VOLUME / nmaps;
- std::cout << "Each mapped region is of size(pages) " << mmap_sz/page_size << std::endl;
-
- auto dst = (long*)malloc(VOLUME);
-
- uint8_t *hint = (uint8_t*)0x600000000000UL;
- hint -= VOLUME;
- auto src = (long*)hint;
- for (long i = 0; i < nmaps; ++i) {
- auto r = mmap(hint, mmap_sz, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
- if (r == MAP_FAILED || r != hint)
- printf("MMAP failed somehow\n");
- hint += mmap_sz;
- }
-
-#pragma omp parallel for
- for (long i = 0; i < VOLUME/sizeof(long); ++i) {
- src[i] = i;
- dst[i] = 0;
- }
-
- int ITER = 100;
- double st = omp_get_wtime();
-
- for (int t = 0; t < ITER; ++t) {
-#pragma omp parallel for
- for (long i = 0; i < VOLUME/sizeof(long); ++i)
- dst[i] = src[i];
- }
-
- st = (omp_get_wtime() - st) / ITER;
-
- printf("Average time(s) %f\n", st);
-// std::cout << "Average time(s) " << st << std::endl;
- printf("Average throughput(GB/s) %f\n", VOLUME * 2 / st * 1e-9);
-// std::cout << "Average throughput(GB/s) " << VOLUME * 2 / st * 1e-9 << std::endl;
- return 0;
-}