Skip to content

Instantly share code, notes, and snippets.

@ugovaretto
Created July 6, 2012 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ugovaretto/3060254 to your computer and use it in GitHub Desktop.
Save ugovaretto/3060254 to your computer and use it in GitHub Desktop.
MVAPICH2 multi-gpu initialization
void device_binding ()
{
int local_rank, num_local_procs;
int dev_count, use_dev_count, my_dev_id;
char *str;
if ((str = getenv ("MV2_COMM_WORLD_LOCAL_RANK")) != NULL)
{
local_rank = atoi (str);
printf ("MV2_COMM_WORLD_LOCAL_RANK %s\n", str);
}
if ((str = getenv ("MPISPAWN_LOCAL_NPROCS")) != NULL)
{
num_local_procs = atoi (str);
printf ("MPISPAWN_LOCAL_NPROCS %s\n", str);
}
cudaGetDeviceCount (&dev_count);
if ((str = getenv ("NUM_GPU_DEVICES")) != NULL)
{
use_dev_count = atoi (str);
printf ("NUM_GPU_DEVICES %s\n", str);
}
else
{
use_dev_count = dev_count;
}
my_dev_id = local_rank % use_dev_count;
printf ("local rank = %d dev id = %d\n", local_rank, my_dev_id);
cudaSetDevice (my_dev_id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment