-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Bash script for running benchmarks * Update `test.sh` * Update with more scripts * Update with new parallel read benchmark * Update to add missing header * Update
- Loading branch information
Showing
18 changed files
with
740 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
#include <binsparse/binsparse.h> | ||
#include <stdlib.h> | ||
#include <time.h> | ||
|
||
double gettime() { | ||
struct timespec time; | ||
clock_gettime(CLOCK_MONOTONIC, &time); | ||
return ((double) time.tv_sec) + ((double) 1e-9) * time.tv_nsec; | ||
} | ||
|
||
int compar(const void* a, const void* b) { | ||
double x = *((const double*) a); | ||
double y = *((const double*) b); | ||
|
||
double diff = x - y; | ||
|
||
if (diff > 0) { | ||
return 1; | ||
} else if (diff < 0) { | ||
return -1; | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
double compute_variance(double* x, size_t n) { | ||
double sum = 0; | ||
|
||
for (size_t i = 0; i < n; i++) { | ||
sum += x[i]; | ||
} | ||
|
||
double mean = sum / n; | ||
|
||
double sum_of_squares = 0; | ||
for (size_t i = 0; i < n; i++) { | ||
sum_of_squares += (x[i] - mean) * (x[i] - mean); | ||
} | ||
|
||
return sum_of_squares / (n - 1); | ||
} | ||
|
||
void flush_cache() { | ||
#ifdef __APPLE__ | ||
int rv = system("bash -c \"sync && sudo purge\""); | ||
#elif __linux__ | ||
int rv = system("bash -c \"sync\" && sudo sh -c \"/usr/bin/echo 3 > " | ||
"/proc/sys/vm/drop_caches\""); | ||
#else | ||
static_assert(false); | ||
#endif | ||
usleep(100000); | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
if (argc < 2) { | ||
fprintf(stderr, "usage: ./benchmark_read [file_name.h5]\n"); | ||
return 1; | ||
} | ||
|
||
char* file_name = argv[1]; | ||
|
||
printf("Opening %s\n", file_name); | ||
|
||
const int num_trials = 2; | ||
|
||
int num_threads = 6; | ||
|
||
double durations[num_trials]; | ||
|
||
size_t nbytes = 0; | ||
|
||
// To flush the filesystem cache before each trial, change to `true`. | ||
bool cold_cache = true; | ||
|
||
// If running warm cache experiments, read once to warm cache. | ||
if (!cold_cache && false) { | ||
printf("Warm cache read...\n"); | ||
bsp_matrix_t mat = bsp_read_matrix_parallel(file_name, NULL, num_threads); | ||
bsp_destroy_matrix_t(mat); | ||
} | ||
|
||
for (size_t i = 0; i < num_trials; i++) { | ||
if (cold_cache) { | ||
flush_cache(); | ||
} | ||
double begin = gettime(); | ||
bsp_matrix_t mat = bsp_read_matrix_parallel(file_name, NULL, num_threads); | ||
double end = gettime(); | ||
durations[i] = end - begin; | ||
nbytes = bsp_matrix_nbytes(mat); | ||
|
||
bsp_destroy_matrix_t(mat); | ||
|
||
double gbytes = ((double) nbytes) / 1024 / 1024 / 1024; | ||
double gbytes_s = gbytes / durations[i]; | ||
printf("FORPARSER: %s,%lf,%lf\n", file_name, durations[i], gbytes_s); | ||
} | ||
|
||
printf("["); | ||
for (size_t i = 0; i < num_trials; i++) { | ||
printf("%lf", durations[i]); | ||
if (i + 1 < num_trials) { | ||
printf(", "); | ||
} | ||
} | ||
printf("]\n"); | ||
|
||
qsort(durations, num_trials, sizeof(double), compar); | ||
|
||
double variance = compute_variance(durations, num_trials); | ||
|
||
double median_time = durations[num_trials / 2]; | ||
|
||
printf("Read file in %lf seconds\n", median_time); | ||
|
||
if (num_trials > 1) { | ||
printf("Variance is %lf seconds, standard devication is %lf seconds\n", | ||
variance, sqrt(variance)); | ||
} | ||
|
||
double gbytes = ((double) nbytes) / 1024 / 1024 / 1024; | ||
double gbytes_s = gbytes / median_time; | ||
|
||
printf("Achieved %lf GiB/s\n", gbytes_s); | ||
|
||
printf("["); | ||
for (size_t i = 0; i < num_trials; i++) { | ||
printf("%lf", durations[i]); | ||
if (i + 1 < num_trials) { | ||
printf(", "); | ||
} | ||
} | ||
printf("]\n"); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#pragma once | ||
|
||
#include <stddef.h> | ||
#include <stdio.h> | ||
#include <sys/ipc.h> | ||
#include <sys/shm.h> | ||
#include <sys/stat.h> | ||
#include <sys/types.h> | ||
#include <sys/wait.h> | ||
|
||
typedef struct { | ||
int id; | ||
size_t size; | ||
} bsp_shm_t; | ||
|
||
bsp_shm_t bsp_shm_new(size_t size) { | ||
bsp_shm_t shm; | ||
shm.size = size; | ||
|
||
if ((shm.id = shmget(IPC_PRIVATE, size, | ||
IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR)) < 0) { | ||
perror("shmget"); | ||
} | ||
|
||
return shm; | ||
} | ||
|
||
void bsp_shm_delete(bsp_shm_t shm) { | ||
shmctl(shm.id, IPC_RMID, 0); | ||
} | ||
|
||
void* bsp_shm_attach(bsp_shm_t shm) { | ||
void* data; | ||
|
||
if ((data = shmat(shm.id, NULL, 0)) == (void*) -1) { | ||
perror("write"); | ||
} | ||
|
||
return data; | ||
} | ||
|
||
void bsp_shm_detach(void* data) { | ||
shmdt(data); | ||
} |
Oops, something went wrong.