quantum-espresso/UtilXlib/tests/test_mp_get_gpu.tmpl

84 lines
2.3 KiB
Cheetah

! Implemented: r1, rv, cv, i1, iv, rm, cm
#if defined(__CUDA)
PROGRAM test_mp_get_{vname}_gpu
!
! Simple program to check the functionalities of test_mp_get_i1.
!
USE cudafor
USE parallel_include
USE util_param, ONLY : DP
USE mp, ONLY : mp_get
USE mp_world, ONLY : mp_world_start, mp_world_end, mpime, &
root, nproc, world_comm
USE tester
IMPLICIT NONE
!
TYPE(tester_t) :: test
INTEGER :: world_group = 0
INTEGER, PARAMETER :: datasize = {datasize}
!
! Stuff for comparing with CPU implementation
integer :: i
REAL(DP) :: rnd{size}
!
! test variable
{type}, DEVICE :: {vname}_d{size}
{type} :: {vname}_h{size}
{type} :: aux_h{size}
!
CALL test%init()
#if defined(__MPI)
world_group = MPI_COMM_WORLD
#endif
CALL mp_world_start(world_group)
{vname}_h = mpime + 1
{vname}_d = {vname}_h
!mp_get (msg_dest, msg_sour, mpime, dest, sour, ip, gid)
CALL mp_get({vname}_d, {vname}_d, mpime, 0, nproc-1, 0, world_comm)
{vname}_h = {vname}_d
!
IF (mpime == 0) CALL test%assert_equal({allf}({vname}_h .eq. nproc) , .true. )
IF (mpime /= 0) CALL test%assert_equal({allf}({vname}_h .eq. mpime+1) , .true. )
!
!
! Test against CPU implementation
CALL save_random_seed("test_mp_get_{vname}_gpu", mpime)
!
DO i = 0, nproc-1
CALL RANDOM_NUMBER(rnd)
{vname}_h = {typeconv} ( 10.0 * rnd )
{vname}_d = {vname}_h
CALL mp_get({vname}_d, {vname}_d, mpime, 0, i, 0, world_comm)
CALL mp_get({vname}_h, {vname}_h, mpime, 0, i, 0, world_comm)
aux_h = {vname}_d
CALL test%assert_{compare}({sumf}({vname}_h) , {sumf}(aux_h) )
END DO
!
DO i = 0, nproc-1
CALL RANDOM_NUMBER(rnd)
{vname}_h = {typeconv} ( 10.0 * rnd )
{vname}_d = {vname}_h
aux_h = 0
CALL mp_get({vname}_d, {vname}_d, mpime, i, 0, 0, world_comm)
CALL mp_get({vname}_h, {vname}_h, mpime, i, 0, 0, world_comm)
aux_h = {vname}_d
CALL test%assert_{compare}({sumf}({vname}_h) , {sumf}(aux_h) )
END DO
!
CALL collect_results(test)
!
CALL mp_world_end()
!
IF (mpime .eq. 0) CALL test%print()
!
END PROGRAM test_mp_get_{vname}_gpu
#else
PROGRAM test_mp_get_{vname}_gpu
CALL no_test()
END PROGRAM test_mp_get_{vname}_gpu
#endif