Hi,all
I want to use two cpu threads to control two GPUs respectively. Here is the test program:
/////////////////////////////////////////////////
PROGRAM TEST
USE cudafor
USE omp_lib
IMPLICIT NONE
INTEGER :: istat
INTEGER :: GPU_ID,GPU_NUM,dev
REAL(KIND=8) :: cc
REAL(KIND=8),allocatable,dimension(:,:),device :: a
call omp_set_num_threads(2)
!$omp parallel private(GPU_ID,dev)
GPU_ID=omp_get_thread_num()
istat=cudaSetDevice(GPU_ID)
istat=cudaGetDevice(dev)
print*,'No.',GPU_ID,'CPU thread control','No.',dev,'GPU'
allocate(a(2,2))
a(:,:)=GPU_ID
!$omp end parallel
print*,'------------------------'
istat=cudaSetDevice(1)
istat=cudaGetDevice(GPU_ID)
print*,'GPU_ID',GPU_ID
cc=a(1,1)
print*,cc
print*,'------------------------'
istat=cudaSetDevice(0)
istat=cudaGetDevice(GPU_ID)
print*,'GPU_ID',GPU_ID
cc=a(1,1)
print*,cc
END PROGRAM
//////////////////////////////////////////
After running this program, I find that the output of “a(1,1)” are same. That means the value of the array “a” on GPUs are same. Why this happen? Can I use allocate to create arrays with same name on different GPU?
Thanks