Skip to content

Commit

Permalink
refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
justanhduc committed Feb 15, 2022
1 parent 65ce4a9 commit 1c61f4b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 34 deletions.
6 changes: 3 additions & 3 deletions client.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void c_new_job() {
else
m.u.newjob.label_size = 0;
m.u.newjob.store_output = command_line.store_output;
m.u.newjob.do_depend = command_line.do_depend;
m.u.newjob.depend_on_size = command_line.depend_on_size;
m.u.newjob.should_keep_finished = command_line.should_keep_finished;
m.u.newjob.command_size = strlen(new_command) + 1; /* add null */
m.u.newjob.wait_enqueuing = command_line.wait_enqueuing;
Expand All @@ -91,7 +91,7 @@ void c_new_job() {
send_ints(server_socket, command_line.gpu_nums, command_line.gpus);

/* send dependencies */
if (command_line.do_depend)
if (command_line.depend_on_size)
send_ints(server_socket, command_line.depend_on, command_line.depend_on_size);

/* Send the command */
Expand Down Expand Up @@ -144,7 +144,7 @@ int c_wait_server_commands() {

freeGpuList = recv_ints(server_socket, &num_gpus);
result.skipped = 0;
if (command_line.do_depend && command_line.require_elevel && m.u.last_errorlevel != 0) {
if (command_line.depend_on_size && command_line.require_elevel && m.u.last_errorlevel != 0) {
result.errorlevel = -1;
result.user_ms = 0.f;
result.system_ms = 0.f;
Expand Down
38 changes: 18 additions & 20 deletions jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,25 @@ void s_list(int s) {
}
}

static void init_job(struct Job *p) {
p->next = 0;
p->output_filename = 0;
p->command = 0;
p->depend_on = 0;
p->gpu_ids = 0;
p->label = 0;
p->notify_errorlevel_to_size = 0;
p->notify_errorlevel_to = 0;
p->dependency_errorlevel = 0;
pinfo_init(&p->info);
}

static struct Job *newjobptr() {
struct Job *p;

if (firstjob == 0) {
firstjob = (struct Job *) malloc(sizeof(*firstjob));
firstjob->next = 0;
firstjob->output_filename = 0;
firstjob->command = 0;
init_job(firstjob);
return firstjob;
}

Expand All @@ -409,10 +420,7 @@ static struct Job *newjobptr() {
p = p->next;

p->next = (struct Job *) malloc(sizeof(*p));
p->next->next = 0;
p->next->output_filename = 0;
p->next->command = 0;

init_job(p->next);
return p->next;
}

Expand Down Expand Up @@ -463,7 +471,6 @@ int s_newjob(int s, struct Msg *m) {
else
p->state = HOLDING_CLIENT;

p->gpu_ids = 0;
p->wait_free_gpus = m->u.newjob.wait_free_gpus;
if (!p->wait_free_gpus)
p->gpu_ids = recv_ints(s, &p->num_gpus);
Expand All @@ -475,16 +482,11 @@ int s_newjob(int s, struct Msg *m) {
p->num_slots = m->u.newjob.num_slots;
p->store_output = m->u.newjob.store_output;
p->should_keep_finished = m->u.newjob.should_keep_finished;
p->notify_errorlevel_to = 0;
p->notify_errorlevel_to_size = 0;
p->do_depend = m->u.newjob.do_depend;
p->depend_on = 0;

/* this error level here is used internally to decide whether a job should be run or not
* so it only matters whether the error level is 0 or not.
* thus, summing the absolute error levels of all dependencies is sufficient.*/
p->dependency_errorlevel = 0;
if (m->u.newjob.do_depend) {
if (m->u.newjob.depend_on_size) {
int *depend_on;
depend_on = recv_ints(s, &p->depend_on_size);

Expand Down Expand Up @@ -567,12 +569,9 @@ int s_newjob(int s, struct Msg *m) {
}

/* if dependency list is empty after removing invalid dependencies, make it independent */
if (p->do_depend && p->depend_on_size == 0) {
if (p->depend_on_size == 0)
p->depend_on = 0;
p->do_depend = 0;
}

pinfo_init(&p->info);
pinfo_set_enqueue_time(&p->info);

/* load the command */
Expand All @@ -585,7 +584,6 @@ int s_newjob(int s, struct Msg *m) {
error("wrong bytes received");

/* load the label */
p->label = 0;
if (m->u.newjob.label_size > 0) {
char *ptr;
ptr = (char *) malloc(m->u.newjob.label_size);
Expand Down Expand Up @@ -697,7 +695,7 @@ int next_run_job() {
memcpy(p->gpu_ids, gpu_ids, p->num_gpus * sizeof(int));
}

if (p->do_depend) {
if (p->depend_on_size) {
int ready = 1;
for (int i = 0; i < p->depend_on_size; i++) {
struct Job *do_depend_job = get_job(p->depend_on[i]);
Expand Down
4 changes: 2 additions & 2 deletions list.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static char *print_noresult(const struct Job *p) {

if (p->label)
maxlen += 3 + strlen(p->label);
if (p->do_depend) {
if (p->depend_on_size) {
maxlen += sizeof(dependstr);
int pos = 0;
if (p->depend_on[0] == -1)
Expand Down Expand Up @@ -175,7 +175,7 @@ static char *print_result(const struct Job *p) {

if (p->label)
maxlen += 3 + strlen(p->label);
if (p->do_depend) {
if (p->depend_on_size) {
maxlen += sizeof(dependstr);
int pos = 0;
if (p->depend_on[0] == -1)
Expand Down
4 changes: 0 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ static void default_command_line() {
command_line.gzip = 0;
command_line.send_output_by_mail = 0;
command_line.label = 0;
command_line.do_depend = 0;
command_line.depend_on = NULL; /* -1 means depend on previous */
command_line.max_slots = 1;
command_line.wait_enqueuing = 1;
Expand Down Expand Up @@ -189,7 +188,6 @@ void parse_opts(int argc, char **argv) {
command_line.request = c_SHOW_HELP;
break;
case 'd':
command_line.do_depend = 1;
command_line.depend_on = (int*) malloc(sizeof(int));
command_line.depend_on_size = 1;
command_line.depend_on[0] = -1;
Expand Down Expand Up @@ -290,12 +288,10 @@ void parse_opts(int argc, char **argv) {
}
break;
case 'D':
command_line.do_depend = 1;
command_line.depend_on = (int*) malloc(strlen(optarg) * sizeof(int));
command_line.depend_on_size = strtok_int(optarg, ",", command_line.depend_on);
break;
case 'W':
command_line.do_depend = 1;
command_line.depend_on = (int*) malloc(strlen(optarg) * sizeof(int));
command_line.depend_on_size = strtok_int(optarg, ",", command_line.depend_on);
command_line.require_elevel = 1;
Expand Down
4 changes: 1 addition & 3 deletions main.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ struct CommandLine {
int should_keep_finished;
int send_output_by_mail;
int gzip;
int do_depend;
int *depend_on; /* -1 means depend on previous */
int depend_on_size;
int max_slots; /* How many jobs to run at once */
Expand Down Expand Up @@ -155,7 +154,7 @@ struct Msg {
int should_keep_finished;
int label_size;
int env_size;
int do_depend;
int depend_on_size;
int wait_enqueuing;
int num_slots;
int gpus;
Expand Down Expand Up @@ -210,7 +209,6 @@ struct Job {
int store_output;
int pid;
int should_keep_finished;
int do_depend;
int *depend_on;
int depend_on_size;
int *notify_errorlevel_to;
Expand Down
8 changes: 6 additions & 2 deletions server.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,14 @@ static void server_loop(int ls) {
}

/* timeout mode if there are queued GPU jobs only */
if (s_count_allocating_jobs() > 0)
if (s_count_allocating_jobs() > 0) {
debug("TIMEOUT mode");
res = select(maxfd + 1, &readset, NULL, NULL, &tv);
else
}
else {
debug("no TIMEOUT mode");
res = select(maxfd + 1, &readset, NULL, NULL, NULL);
}

if (res != -1) {
if (FD_ISSET(ls, &readset)) {
Expand Down

0 comments on commit 1c61f4b

Please sign in to comment.