Commit 8379de5a authored by Shane Snyder's avatar Shane Snyder

Add function for retrieving function rank count

Workload API now defines a function for retrieving the rank count
of a workload. Currently, only darshan workload implements this.
Will work on bgp workload and recorder later.
parent 78920873
......@@ -136,6 +136,9 @@ void codes_workload_get_next(int wkld_id, int rank, struct codes_workload_op *op
/* Reverse of the above function. */
void codes_workload_get_next_rc(int wkld_id, int rank, const struct codes_workload_op *op);
/* Retrieve the number of ranks contained in a workload */
int codes_workload_get_rank_cnt(const char* type, const char* params);
/* for debugging/logging: print an individual operation to the specified file */
void codes_workload_print_op(FILE *f, struct codes_workload_op *op, int rank);
......
......@@ -43,6 +43,7 @@ struct rank_io_context
/* Darshan workload generator's implementation of the CODES workload API */
static int darshan_io_workload_load(const char *params, int rank);
static void darshan_io_workload_get_next(int rank, struct codes_workload_op *op);
static int darshan_io_workload_get_rank_cnt(const char *params);
static int darshan_rank_hash_compare(void *key, struct qhash_head *link);
/* Darshan I/O op data structure access (insert, remove) abstraction */
......@@ -89,8 +90,11 @@ struct codes_workload_method darshan_io_workload_method =
.method_name = "darshan_io_workload",
.codes_workload_load = darshan_io_workload_load,
.codes_workload_get_next = darshan_io_workload_get_next,
.codes_workload_get_rank_cnt = darshan_io_workload_get_rank_cnt,
};
static int total_rank_cnt = 0;
/* hash table to store per-rank workload contexts */
static struct qhash_table *rank_tbl = NULL;
static int rank_tbl_pop = 0;
......@@ -120,6 +124,11 @@ static int darshan_io_workload_load(const char *params, int rank)
darshan_log_close(logfile_fd);
return -1;
}
if (!total_rank_cnt)
{
total_rank_cnt = job.nprocs;
}
assert(rank < total_rank_cnt);
/* allocate the i/o context needed by this rank */
my_ctx = malloc(sizeof(struct rank_io_context));
......@@ -197,6 +206,8 @@ static void darshan_io_workload_get_next(int rank, struct codes_workload_op *op)
struct rank_io_context *tmp = NULL;
struct darshan_io_op next_io_op;
assert(rank < total_rank_cnt);
/* find i/o context for this rank in the rank hash table */
hash_link = qhash_search(rank_tbl, &my_rank);
......@@ -238,6 +249,34 @@ static void darshan_io_workload_get_next(int rank, struct codes_workload_op *op)
return;
}
static int darshan_io_workload_get_rank_cnt(const char *params)
{
darshan_params *d_params = (darshan_params *)params;
darshan_fd logfile_fd;
struct darshan_job job;
int ret;
if (!d_params)
return -1;
/* open the darshan log to begin reading in file i/o info */
logfile_fd = darshan_log_open(d_params->log_file_path, "r");
if (logfile_fd < 0)
return -1;
/* get the per-job stats from the log */
ret = darshan_log_getjob(logfile_fd, &job);
if (ret < 0)
{
darshan_log_close(logfile_fd);
return -1;
}
darshan_log_close(logfile_fd);
return job.nprocs;
}
/* comparison function for comparing two hash keys (used for storing multiple io contexts) */
static int darshan_rank_hash_compare(
void *key, struct qhash_head *link)
......
......@@ -32,7 +32,7 @@ void usage(){
"Usage: codes-workload-dump --type TYPE --num-ranks N "
"[--d-log LOG --d-aggregator-cnt CNT]\n"
"--type: type of workload (\"darshan_io_workload\" or \"bgp_io_workload\")\n"
"--num-ranks: number of ranks to process\n"
"--num-ranks: number of ranks to process (if not set, it is set by the workload)\n"
"--d-log: darshan log file\n"
"--d-aggregator-cnt: number of aggregators for collective I/O in darshan\n"
"--i-meta: i/o language kernel meta file path\n"
......@@ -88,11 +88,6 @@ int main(int argc, char *argv[])
usage();
return 1;
}
if (n == -1){
fprintf(stderr, "Expected \"--num-ranks\" argument\n");
usage();
return 1;
}
int i;
char *wparams;
......@@ -136,6 +131,12 @@ int main(int argc, char *argv[])
usage();
return 1;
}
/* if num_ranks not set, pull it from the workload */
if (n == -1){
n = codes_workload_get_rank_cnt(type, wparams);
}
for (i = 0 ; i < n; i++){
struct codes_workload_op op;
printf("loading %s, %d\n", type, i);
......
......@@ -20,7 +20,7 @@ struct codes_workload_method
char *method_name; /* name of the generator */
int (*codes_workload_load)(const char* params, int rank);
void (*codes_workload_get_next)(int rank, struct codes_workload_op *op);
void* (*codes_workload_get_info)(int rank);
int (*codes_workload_get_rank_cnt)(const char* params);
};
#endif /* CODES_WORKLOAD_METHOD_H */
......
......@@ -161,9 +161,23 @@ void codes_workload_get_next_rc(int wkld_id, int rank, const struct codes_worklo
return;
}
void* codes_workload_get_info(int wkld_id, int rank)
int codes_workload_get_rank_cnt(const char* type, const char* params)
{
return method_array[wkld_id]->codes_workload_get_info(rank);
int i;
int rank_cnt;
for(i=0; method_array[i] != NULL; i++)
{
if(strcmp(method_array[i]->method_name, type) == 0)
{
rank_cnt = method_array[i]->codes_workload_get_rank_cnt(params);
assert(rank_cnt > 0);
return(rank_cnt);
}
}
fprintf(stderr, "Error: failed to find workload generator %s\n", type);
return(-1);
}
void codes_workload_print_op(FILE *f, struct codes_workload_op *op, int rank){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment