Skip to content

Commit

Permalink
showed jobs' GPU IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
justanhduc committed Nov 4, 2021
1 parent 17ce082 commit 58a2e7b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
8 changes: 1 addition & 7 deletions client.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,7 @@ int c_wait_server_commands() {
if (command_line.gpus) {
char tmp[1024];
strcpy(tmp, "CUDA_VISIBLE_DEVICES=");
for (int i = 0; i < num_gpus; i++) {
char tmp2[512];
sprintf(tmp2, "%d", freeGpuList[i]);
strcat(tmp, tmp2);
if (i < command_line.gpus - 1)
strcat(tmp, ",");
}
strcat(tmp, ints_to_chars(freeGpuList, num_gpus, ","));
putenv(tmp);
free(freeGpuList);
} else {
Expand Down
5 changes: 5 additions & 0 deletions jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,10 @@ int s_newjob(int s, struct Msg *m) {
p->wait_free_gpus = m->u.newjob.wait_free_gpus;
if (!p->wait_free_gpus)
p->gpu_ids = recv_ints(s, &p->num_gpus);
else {
p->gpu_ids = (int *) malloc((p->num_gpus + 1) * sizeof(int));
memset(p->gpu_ids, -1, (p->num_gpus + 1) * sizeof(int));
}

p->num_slots = m->u.newjob.num_slots;
p->store_output = m->u.newjob.store_output;
Expand Down Expand Up @@ -973,6 +977,7 @@ void s_job_info(int s, int jobid) {
fd_nprintf(s, 100, "\n");
fd_nprintf(s, 100, "Slots required: %i\n", p->num_slots);
fd_nprintf(s, 100, "GPUs required: %d\n", p->num_gpus);
fd_nprintf(s, 100, "GPU IDs: %s\n", ints_to_chars(p->gpu_ids, p->num_gpus ? p->num_gpus : 1, ","));
fd_nprintf(s, 100, "Enqueue time: %s",
ctime(&p->info.enqueue_time.tv_sec));
if (p->state == RUNNING) {
Expand Down
2 changes: 2 additions & 0 deletions main.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ char *joblistdump_headers();
/* print.c */
int fd_nprintf(int fd, int maxsize, const char *fmt, ...);

char *ints_to_chars(int *array, int n, const char *delim);

/* info.c */

void pinfo_dump(const struct Procinfo *p, int fd);
Expand Down
13 changes: 13 additions & 0 deletions print.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,16 @@ int fd_nprintf(int fd, int maxsize, const char *fmt, ...)

return size;
}

char *ints_to_chars(int *array, int n, const char *delim) {
char *tmp = malloc(n * sizeof(char) + n * strlen(delim) * sizeof(char) + 1);
int j = 0;
for (int i = 0; i < n; i++) {
j += sprintf(tmp + j, "%d", array[i]);
if (i < n - 1) {
strcat(tmp, delim);
j += strlen(delim);
}
}
return tmp;
}

0 comments on commit 58a2e7b

Please sign in to comment.