Created
July 6, 2012 13:48
-
-
Save ugovaretto/3060254 to your computer and use it in GitHub Desktop.
MVAPICH2 multi-gpu initialization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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