Skip to content
Snippets Groups Projects
Commit 06c71e94 authored by Erik Strand's avatar Erik Strand
Browse files

Check SLURM_LOCALID environment variable

This gives you a unique index within a single node. Will be useful for
assigning GPUs to threads.
parent ea5fd2cd
Branches
No related tags found
No related merge requests found
#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int numtasks, rank, length;
char hostname[MPI_MAX_PROCESSOR_NAME];
char* local_rank_str = NULL;
int local_rank = 0;
local_rank_str = getenv("SLURM_LOCALID");
if (local_rank_str != NULL) {
local_rank = atoi(local_rank_str);
printf("slurm local rank = %d\n", local_rank);
} else {
printf("slurm local rank not defined\n");
}
int n_tasks, rank, length;
char host_name[MPI_MAX_PROCESSOR_NAME];
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
MPI_Comm_size(MPI_COMM_WORLD, &n_tasks);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Get_processor_name(hostname, &length);
printf("Number of tasks = %d, rank = %d, running on %s\n", numtasks, rank, hostname);
MPI_Get_processor_name(host_name, &length);
printf("Number of tasks = %d, rank = %d, running on %s\n", n_tasks, rank, host_name);
MPI_Finalize();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment