From cc71b45e76b0910c75a6c5f81b90944239f1aace Mon Sep 17 00:00:00 2001
From: Pietro Bonfa
Date: Tue, 27 Feb 2018 13:54:17 +0100
Subject: [PATCH] Added test for mp_circular_shift_left (GPU code only)
---
UtilXlib/tests/test_mp_bcast_im_gpu.f90 | 2 +-
.../test_mp_circular_shift_left_gpu.tmpl | 73 +++++++++++++++++++
2 files changed, 74 insertions(+), 1 deletion(-)
create mode 100644 UtilXlib/tests/test_mp_circular_shift_left_gpu.tmpl
diff --git a/UtilXlib/tests/test_mp_bcast_im_gpu.f90 b/UtilXlib/tests/test_mp_bcast_im_gpu.f90
index ba4ee1544..e1b7ad69f 100644
--- a/UtilXlib/tests/test_mp_bcast_im_gpu.f90
+++ b/UtilXlib/tests/test_mp_bcast_im_gpu.f90
@@ -1,7 +1,7 @@
#if defined(__CUDA)
PROGRAM test_mp_bcast_im_gpu
!
-! Simple program to check the functionalities of test_mp_bcast_i1.
+! Simple program to check the functionalities of test_mp_bcast_im.
!
USE cudafor
#if defined(__MPI)
diff --git a/UtilXlib/tests/test_mp_circular_shift_left_gpu.tmpl b/UtilXlib/tests/test_mp_circular_shift_left_gpu.tmpl
new file mode 100644
index 000000000..fd607deeb
--- /dev/null
+++ b/UtilXlib/tests/test_mp_circular_shift_left_gpu.tmpl
@@ -0,0 +1,73 @@
+! Implemented: i1, iv, im, rm, cm
+
+#if defined(__CUDA)
+
+PROGRAM test_mp_circular_shift_left_{vname}_gpu
+!
+! Simple program to check the functionalities of test_mp_circular_shift_left.
+! N.B : mp_circular_shift_left is doing a allreduce!
+!
+ USE cudafor
+#if defined(__MPI)
+ USE MPI
+#endif
+ USE mp, ONLY : mp_circular_shift_left
+ 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(8) :: 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
+ {vname}_d = {vname}_h
+ !mp_circular_shift_left (msg_dest, msg_sour, mpime, dest, sour, ip, gid)
+ CALL mp_circular_shift_left({vname}_d, 0, world_comm)
+ {vname}_h = {vname}_d
+ !
+ CALL test%assert_{compare}({sumf}({vname}_h - {typeconv}(MODULO(mpime+1, nproc))), {typeconv}(0) )
+ !
+ !
+ ! Test against CPU implementation
+ CALL save_random_seed("test_mp_circular_shift_left_{vname}_gpu", mpime)
+ !
+ DO i = 0, nproc-1
+ CALL RANDOM_NUMBER(rnd)
+ {vname}_h = {typeconv} ( 10.0 * rnd )
+ {vname}_d = {vname}_h
+ CALL mp_circular_shift_left({vname}_d, 0, world_comm)
+ CALL mp_circular_shift_left({vname}_h, 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_circular_shift_left_{vname}_gpu
+#else
+PROGRAM test_mp_circular_shift_left_{vname}_gpu
+ CALL no_test()
+END PROGRAM test_mp_circular_shift_left_{vname}_gpu
+#endif