Commit 5c5f4c82 authored by Jonathan Jenkins's avatar Jonathan Jenkins

disable printfs, more renames

parent b9b09b1b
......@@ -9,13 +9,25 @@
#include <assert.h>
#include "../codes-jobmap-method-impl.h"
#define LIST_DEBUG 0
#define dprintf(_fmt, ...) \
do { \
if (LIST_DEBUG) { \
fprintf(stdout, "jobmap-list: "); \
fprintf(stdout, _fmt, ##__VA_ARGS__); \
} \
} while (0)
#define ERR(str, ...)\
do{\
fprintf(stderr, "ERROR at %s:%d: " str "\n", __FILE__, __LINE__, ##__VA_ARGS__);\
if (LIST_DEBUG) { \
fprintf(stderr, "ERROR at %s:%d: " str "\n", \
__FILE__, __LINE__, ##__VA_ARGS__);\
} \
return -1; \
}while(0)
struct joblist {
struct jobmap_list {
int num_jobs;
int *num_rank_job;
int **lp_arrays;
......@@ -24,73 +36,71 @@ struct joblist {
static int jobmap_list_configure(void const * params, void ** ctx)
{
struct codes_jobmap_params_list const * p = params;
struct joblist *wp = malloc(sizeof(*wp));
assert(wp);
struct jobmap_list *lst = malloc(sizeof(*lst));
assert(lst);
FILE *alloc_file_name = fopen(p->alloc_file, "r");
if(!alloc_file_name)
{
ERR( "Coudld not open file %s\n ", p->alloc_file);
ERR("Could not open file %s\n ", p->alloc_file);
}
else{
wp->num_jobs = 0;
lst->num_jobs = 0;
while(!feof(alloc_file_name))
{
char ch = (char)fgetc(alloc_file_name);
if(ch == '\n')
wp->num_jobs++;//how many jobs
lst->num_jobs++;//how many jobs
}
}
wp->num_rank_job = malloc(sizeof(wp->num_rank_job)*wp->num_jobs);
assert(wp->num_rank_job);
for(int i=0; i<wp->num_jobs; i++)
wp->num_rank_job[i]=0;
lst->num_rank_job = malloc(sizeof(lst->num_rank_job)*lst->num_jobs);
assert(lst->num_rank_job);
for(int i=0; i<lst->num_jobs; i++)
lst->num_rank_job[i]=0;
rewind(alloc_file_name);
int job_id = 0;
while(!feof(alloc_file_name))
{
int job_id = 0;
while(!feof(alloc_file_name))
{
char ch = (char)fgetc(alloc_file_name);
if(ch == '\n'){
job_id++;//how many jobs
continue;
}
if(ch == ' '){
wp->num_rank_job[job_id]++;//how many ranks in each job
}
char ch = (char)fgetc(alloc_file_name);
if(ch == '\n'){
job_id++;//how many jobs
continue;
}
if(ch == ' '){
lst->num_rank_job[job_id]++;//how many ranks in each job
}
}
wp->lp_arrays = (int **)malloc(sizeof(int *)*wp->num_jobs);
for(int i=0; i<wp->num_jobs; i++){
wp->lp_arrays[i] = (int *)malloc(sizeof(int)*wp->num_rank_job[i]);
lst->lp_arrays = (int **)malloc(sizeof(int *)*lst->num_jobs);
for(int i=0; i<lst->num_jobs; i++){
lst->lp_arrays[i] = (int *)malloc(sizeof(int)*lst->num_rank_job[i]);
}
rewind(alloc_file_name);
for(int i=0; i < wp->num_jobs; i++)
for(int i=0; i < lst->num_jobs; i++)
{
for(int j=0; j < wp->num_rank_job[i]; j++)
for(int j=0; j < lst->num_rank_job[i]; j++)
{
fscanf(alloc_file_name, "%d", &wp->lp_arrays[i][j]);
fscanf(alloc_file_name, "%d", &lst->lp_arrays[i][j]);
}
}
fclose(alloc_file_name);
*ctx = wp;
*ctx = lst;
printf("There are %d Jobs\n", wp->num_jobs);
for(int i=0; i < wp->num_jobs; i++)
dprintf("read %d jobs\n", lst->num_jobs);
for(int i=0; i < lst->num_jobs; i++)
{
printf("\nIn Job %d, there are %d ranks, LP list is:\n", i, wp->num_rank_job[i]);
for(int j=0; j < wp->num_rank_job[i]; j++)
dprintf(" job %d contains %d ranks, LP list is:\n ",
i, lst->num_rank_job[i]);
for(int j=0; j < lst->num_rank_job[i]; j++)
{
printf("%d,", wp->lp_arrays[i][j]);
dprintf(" %d,", lst->lp_arrays[i][j]);
}
printf("\n==========\n");
dprintf("\n==========\n");
}
return 0;
......@@ -99,13 +109,13 @@ static int jobmap_list_configure(void const * params, void ** ctx)
static struct codes_jobmap_id jobmap_list_to_local(int id, void const * ctx)
{
struct codes_jobmap_id rtn;
struct joblist *wp = (struct joblist*)ctx;
struct jobmap_list *lst = (struct jobmap_list*)ctx;
for(int i=0; i<wp->num_jobs; i++)
for(int i=0; i<lst->num_jobs; i++)
{
for(int j=0; j < wp->num_rank_job[i]; j++)
for(int j=0; j < lst->num_rank_job[i]; j++)
{
if(id == wp->lp_arrays[i][j])
if(id == lst->lp_arrays[i][j])
{
rtn.job = i;
rtn.rank = j;
......@@ -124,32 +134,32 @@ static struct codes_jobmap_id jobmap_list_to_local(int id, void const * ctx)
static int jobmap_list_to_global(struct codes_jobmap_id id, void const * ctx)
{
struct joblist *wp = (struct joblist*)ctx;
struct jobmap_list *lst = (struct jobmap_list*)ctx;
if (id.job < wp->num_jobs)
return wp->lp_arrays[id.job][id.rank];
if (id.job < lst->num_jobs)
return lst->lp_arrays[id.job][id.rank];
else
return -1;
}
int jobmap_list_get_num_jobs(void const * ctx)
{
struct joblist *wp = (struct joblist*)ctx;
return wp->num_jobs;
struct jobmap_list *lst = (struct jobmap_list*)ctx;
return lst->num_jobs;
}
static void jobmap_list_destroy(void * ctx)
{
struct joblist *wp = (struct joblist*)ctx;
for(int i=0; i<wp->num_jobs; i++){
free(wp->lp_arrays[i]);
struct jobmap_list *lst = (struct jobmap_list*)ctx;
for(int i=0; i<lst->num_jobs; i++){
free(lst->lp_arrays[i]);
}
free(wp->lp_arrays);
free(lst->lp_arrays);
free(wp->num_rank_job);
free(lst->num_rank_job);
free(ctx);
}
......
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