28 #include <sys/types.h> 37 #define READBUFSIZ 1048576 47 char *dirname = (
char *)p;
48 DIR *dir = opendir(dirname);
51 for (
struct dirent *dp = readdir(dir); dp != NULL; dp = readdir(dir)) {
52 assert(strlen(dp->d_name) > 0);
53 if (dp->d_name[0] ==
'.') {
56 char filepath[PATHLEN];
57 snprintf(filepath, PATHLEN,
"%s/%s", dirname, dp->d_name);
58 struct kmr_kv_box nkv = { .klen =
sizeof(long),
59 .vlen = (
int)((strlen(filepath) + 1) *
sizeof(
char)),
61 .v.p = (
void *)&filepath };
76 char *filename = (
char *)kv.v.p;
79 double t1 = MPI_Wtime();
80 FILE *fp = fopen(filename,
"r");
84 siz = fread(buf,
sizeof(
char), READBUFSIZ, fp);
87 double t2 = MPI_Wtime();
89 struct kmr_kv_box nkv = { .klen =
sizeof(long),
90 .vlen =
sizeof(
double),
101 summarize(
const struct kmr_kv_box kv[],
const long n,
105 for (
long i = 0; i < n; i++) {
106 printf(
"%f\n", kv[i].v.d);
109 double avg = sum / (double)n;
110 printf(
"Average read time: %f\n", avg);
120 check_directory(
const char *path)
123 int ret = stat(path, &s);
127 if (S_ISDIR(s.st_mode)) {
137 fprintf(stderr,
"Specify a directory.\n\n");
138 fprintf(stderr,
"Usage: ./a.out [-s] DIRECTORY\n");
139 fprintf(stderr,
" -s : perform shuffle to distribute files.\n");
145 main(
int argc,
char **argv)
149 char *dirname = NULL;
151 MPI_Init(&argc, &argv);
152 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
153 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
155 if (!(argc == 2 || argc == 3)) {
159 }
else if (argc == 2) {
161 if (!check_directory(dirname)) {
166 }
else if (argc == 3) {
167 int ret = strcmp(argv[1],
"-s");
172 if (!check_directory(dirname)) {
185 kmr_map_once(kvs_infiles, (
void *)dirname, kmr_noopt, 1, read_files);
197 kmr_map(kvs_targets, kvs_times, NULL, kmr_noopt, benchmark);
202 kmr_reduce(kvs_all_times, NULL, NULL, kmr_noopt, summarize);
Key-Value Stream (abstract).
#define kmr_reduce(KVI, KVO, ARG, OPT, R)
Reduces key-value pairs.
int kmr_add_kv(KMR_KVS *kvs, const struct kmr_kv_box kv)
Adds a key-value pair.
int kmr_map_once(KMR_KVS *kvo, void *arg, struct kmr_option opt, _Bool rank_zero_only, kmr_mapfn_t m)
Maps once.
#define kmr_create_kvs(MR, KF, VF)
Makes a new key-value stream (of type KMR_KVS) with the specified field datatypes.
int kmr_shuffle(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt)
Shuffles key-value pairs to the appropriate destination ranks.
int kmr_assign_file(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt)
Assigns files to ranks based on data locality.
#define kmr_map(KVI, KVO, ARG, OPT, M)
Maps simply.
Handy Copy of a Key-Value Field.
int kmr_fin(void)
Clears the environment.
#define kmr_init()
Sets up the environment.
int kmr_free_context(KMR *mr)
Releases a context created with kmr_create_context().
KMR * kmr_create_context(const MPI_Comm comm, const MPI_Info conf, const char *name)
Makes a new KMR context (a context has type KMR).