Skip to content

Commit

Permalink
minor cleanups. killed servers without terminating jobs.
Browse files Browse the repository at this point in the history
  • Loading branch information
justanhduc committed May 26, 2021
1 parent 6ccdf4e commit f6f97b6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
9 changes: 4 additions & 5 deletions client.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ void c_new_job() {
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 Down Expand Up @@ -155,7 +154,7 @@ int c_wait_server_commands() {
putenv(tmp);
} else {
int numFree;
int *freeList = getFreeGpuList(&numFree);
int *freeGpuList = getFreeGpuList(&numFree);
if ((command_line.gpus > numFree)) {
result.errorlevel = -1;
result.user_ms = 0.;
Expand All @@ -166,17 +165,17 @@ int c_wait_server_commands() {
} else {
char tmp[50];
strcpy(tmp, "CUDA_VISIBLE_DEVICES=");
shuffle(freeList, numFree);
shuffle(freeGpuList, numFree);
for (int i = 0; i < command_line.gpus; i++) {
char tmp2[5];
sprintf(tmp2, "%d", freeList[i]);
sprintf(tmp2, "%d", freeGpuList[i]);
strcat(tmp, tmp2);
if (i < command_line.gpus - 1)
strcat(tmp, ",");
}
putenv(tmp);
}
free(freeList);
free(freeGpuList);
}
} else {
putenv("CUDA_VISIBLE_DEVICES=-1");
Expand Down
6 changes: 2 additions & 4 deletions jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ int s_newjob(int s, struct Msg *m) {
p->notify_errorlevel_to = 0;
p->notify_errorlevel_to_size = 0;
p->do_depend = m->u.newjob.do_depend;
p->depend_on_size = m->u.newjob.depend_on_size;
p->depend_on = 0;

/* this error level here is used internally to decide whether a job should be run or not
Expand All @@ -459,7 +458,7 @@ int s_newjob(int s, struct Msg *m) {
p->dependency_errorlevel = 0;
if (m->u.newjob.do_depend) {
int *depend_on;
depend_on = recv_ints(s);
depend_on = recv_ints(s, &p->depend_on_size);

/* Depend on the last queued job. */
int idx = 0;
Expand Down Expand Up @@ -615,8 +614,7 @@ void s_removejob(int jobid) {

newnext = p->next->next;

free(p->next->command);
free(p->next);
destroy_job(p->next);
p->next = newnext;
}

Expand Down
2 changes: 0 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,6 @@ int main(int argc, char **argv) {
case c_KILL_SERVER:
if (!command_line.need_server)
error("The command %i needs the server", command_line.request);
/* terminate all jobs first */
c_kill_all_jobs();
c_shutdown_server();
break;
case c_CLEAR_FINISHED:
Expand Down
3 changes: 1 addition & 2 deletions main.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ struct Msg {
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 @@ -414,7 +413,7 @@ int recv_msg(int fd, struct Msg *m);

void send_ints(int fd, const int *data, int num);

int *recv_ints(int fd);
int *recv_ints(int fd, int *num);

/* msgdump.c */
void msgdump(FILE *, const struct Msg *m);
Expand Down
24 changes: 14 additions & 10 deletions msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,25 @@ void send_ints(const int fd, const int* data, int num) {
if (res == -1)
warning("Sending to %i.", fd);

res = write(fd, data, num * sizeof(int));
if (res == -1)
warning("Sending %i bytes to %i.", num * sizeof(int), fd);
if (num) {
res = write(fd, data, num * sizeof(int));
if (res == -1)
warning("Sending %i bytes to %i.", num * sizeof(int), fd);
}
}

int *recv_ints(const int fd) {
int *recv_ints(const int fd, int *num) {
int res;
int num;
res = read(fd, &num, sizeof(int));
res = read(fd, num, sizeof(int));
if (res == -1)
warning("Receiving from %i.", fd);

int *data = (int*) malloc(num * sizeof(int));
res = read(fd, data, sizeof(int) * num);
if (res == -1)
warning("Receiving %i bytes from %i.", sizeof(int) * num, fd);
int *data = 0;
if (*num) {
data = (int *) malloc(*num * sizeof(int));
res = read(fd, data, sizeof(int) * *num);
if (res == -1)
warning("Receiving %i bytes from %i.", sizeof(int) * *num, fd);
}
return data;
}

0 comments on commit f6f97b6

Please sign in to comment.