[petsc-dev] bad code that needs fixing

Jose E. Roman jroman at dsic.upv.es
Mon Mar 18 15:15:07 CDT 2013


Also, rank should be PetscMPIInt as well as size.
Jose


El 18/03/2013, a las 20:54, Paul Mullowney escribió:

> Should have caught that.
> -Paul
> 
>>    device must be cast to int before being passed to cudaSetDevice().
>> 
>>   cudaSetDevice(device);
>> 
>> On Mar 17, 2013, at 3:36 PM, Paul Mullowney<paulm at txcorp.com>  wrote:
>> 
>>> Here's a patch following the instructions on the wiki for small patches.
>>> 
>>> -Paul
>>>>   {
>>>>     int size;
>>>>     ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr);
>>>>     if (size>1) {
>>>>       int devCount, device, rank;
>>>>       ierr   = cudaGetDeviceCount(&devCount);CHKERRQ(ierr);
>>>>       ierr   = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr);
>>>>       device = rank % devCount;
>>>>       ierr   = cudaSetDevice(device);CHKERRQ(ierr);
>>>>     } else {
>>>>       int device;
>>>>       /* the code below works for serial GPU simulations */
>>>>       ierr = PetscOptionsGetInt(NULL,"-cuda_set_device",&device,&flg1);CHKERRQ(ierr);
>>>>       if (flg1) {
>>>>         ierr = cudaSetDevice(device);CHKERRQ(ierr);
>>>>       }
>>>>     }
>>>>   }
>>>> 
>>>> size int should be PETScMPIInt and device int cannot be an int if it is passed to PetscOptionsGetInt which requires a PetscInt.
>>>> 
>>>> 
>>> <0001-cuda-device-selection.patch>
> 
> <0002-cuda-device-selection.patch>




More information about the petsc-dev mailing list