/** * \brief NCCL implementation of \ref gpucomm_new. */ static int comm_new(gpucomm **comm_ptr, gpucontext *ctx, gpucommCliqueId comm_id, int ndev, int rank) { gpucomm *comm; ncclResult_t err; ASSERT_CTX(ctx); GA_CHECK(setup_lib(ctx->err)); comm = calloc(1, sizeof(*comm)); // Allocate memory if (comm == NULL) { *comm_ptr = NULL; // Set to NULL if failed return error_sys(ctx->err, "calloc"); } comm->ctx = (cuda_context *)ctx; // convert to underlying cuda context // So that context would not be destroyed before communicator comm->ctx->refcnt++; cuda_enter(comm->ctx); // Use device err = ncclCommInitRank(&comm->c, ndev, *((ncclUniqueId *)&comm_id), rank); cuda_exit(comm->ctx); TAG_COMM(comm); if (err != ncclSuccess) { *comm_ptr = NULL; // Set to NULL if failed comm_clear(comm); return error_nccl(ctx->err, "ncclCommInitRank", err); } *comm_ptr = comm; return GA_NO_ERROR; }
/** * \brief NCCL implementation of \ref gpucomm_free. */ static void comm_free(gpucomm *comm) { ASSERT_COMM(comm); cuda_enter(comm->ctx); ncclCommDestroy(comm->c); cuda_exit(comm->ctx); comm_clear(comm); }
void all_com(args prime){ /* zombie reaping updates every loop and is handled here */ pid_t pid; waitpid(-1, &pid, WNOHANG); /*****************[dir]*/ if(!strcmp(prime.command, "dir")){ /* forking and sorting by process id-- inspired by assignment example */ pid = fork(); switch(pid){ /* fork failed */ case -1: fprintf(stderr, "ERROR-- call to fork failed at request from dir\n"); exit(EXIT_FAILURE); /* child */ case 0: comm_dir(prime); exit(EXIT_SUCCESS); /* parent process waits for child (or moves along if redirection was detected */ default: if(prime.flag_f == 0){ waitpid(pid, NULL, 0); } } } /*****************[clr]*/ else if(!strcmp(prime.command, "clr")){ /* new fork */ pid = fork(); switch(pid){ /* fork botched */ case -1: fprintf(stderr, "ERROR-- call to fork failed at request from dir\n"); exit(EXIT_FAILURE); /* child */ case 0: comm_clear(); exit(EXIT_SUCCESS); /* parent */ default: if(prime.flag_f == 0){ waitpid(pid, NULL, 0); } } } /*****************[quit]*/ else if(!strcmp(prime.command, "quit")){ comm_quit(); } /**************[environ]*/ else if(!strcmp(prime.command, "environ")){ pid = fork(); switch(pid){ case -1: fprintf(stderr, "ERROR-- call to fork failed at request from dir\n"); exit(EXIT_FAILURE); case 0: comm_environ(); exit(EXIT_SUCCESS); default: if(prime.flag_f == 0){ waitpid(pid, NULL, 0); } } } /******************[cd]*/ else if(!strcmp(prime.command, "cd")){ comm_cd(prime); } /***************[pause]*/ else if(!strcmp(prime.command, "pause")){ pid = fork(); switch(pid){ case -1: fprintf(stderr, "ERROR-- call to fork failed at request from dir\n"); exit(EXIT_FAILURE); case 0: comm_pause(prime); exit(EXIT_SUCCESS); default: if(prime.flag_f == 0){ waitpid(pid, NULL, 0); } } } /******************[echo]*/ else if(!strcmp(prime.command, "echo")){ pid = fork(); switch(pid){ case -1: fprintf(stderr, "ERROR-- call to fork failed at request from dir\n"); exit(EXIT_FAILURE); case 0: comm_echo(prime); exit(EXIT_SUCCESS); default: if(prime.flag_f == 0){ waitpid(pid, NULL, 0); } } } /******************[help]*/ else if(!strcmp(prime.command, "help")){ pid = fork(); switch(pid){ case -1: fprintf(stderr, "ERROR-- call to fork failed at request from dir\n"); exit(EXIT_FAILURE); case 0: comm_help(prime); exit(EXIT_SUCCESS); default: if(prime.flag_f == 0){ waitpid(pid, NULL, 0); } } } /****************[everything else]*/ else{ pid = fork(); switch(pid){ case -1: fprintf(stderr, "ERROR-- call to fork failed at request from dir\n"); exit(EXIT_FAILURE); case 0: comm_system(prime); exit(EXIT_SUCCESS); default: if(prime.flag_f == 0){ waitpid(pid, NULL, 0); } } } }