Setting based on MPI rank

This commit is contained in:
James E McClure 2018-04-14 21:01:16 -04:00
parent 4e7c8fda99
commit 9b618db185
3 changed files with 8 additions and 7 deletions

View File

@ -11,7 +11,7 @@
#define ScalLBL_H
#include "common/Domain.h"
extern "C" int ScaLBL_SetDevice();
extern "C" int ScaLBL_SetDevice(int rank);
extern "C" void ScaLBL_AllocateDeviceMemory(void** address, size_t size);

View File

@ -2,11 +2,12 @@
#include <cuda.h>
#include <stdio.h>
extern "C" int ScaLBL_SetDevice(){
extern "C" int ScaLBL_SetDevice(int rank){
int n_devices;
int local_rank = atoi(getenv("MV2_COMM_WORLD_LOCAL_RANK"));
//int local_rank = atoi(getenv("MV2_COMM_WORLD_LOCAL_RANK"));
cudaGetDeviceCount(&n_devices);
int device = local_rank % n_devices;
//int device = local_rank % n_devices;
int device = rank % n_devices;
cudaSetDevice(device);
return device;
}

View File

@ -27,9 +27,6 @@ using namespace std;
int main(int argc, char **argv)
{
// Initialize compute device
int device=ScaLBL_SetDevice();
// Initialize MPI
int provided_thread_support = -1;
MPI_Init_thread(&argc,&argv,MPI_THREAD_MULTIPLE,&provided_thread_support);
@ -39,6 +36,9 @@ int main(int argc, char **argv)
int nprocs = comm_size(comm);
{ // Limit scope so variables that contain communicators will free before MPI_Finialize
// Initialize compute device
int device=ScaLBL_SetDevice(rank);
// parallel domain size (# of sub-domains)
int nprocx,nprocy,nprocz;
int iproc,jproc,kproc;