From d91de388dd6b3a41a0463d5c16e28d8d5b1943e3 Mon Sep 17 00:00:00 2001
From: Xavier Andrade <xavier@tddft.org>
Date: Sat, 17 Dec 2011 23:48:50 +0000
Subject: [PATCH] Improved the interface for clEnqueueNDRangeKernel.

---
 external_libs/fortrancl/cl_command_queue.f90 | 46 +++++++++++++-------
 src/basic/opencl.F90                         |  2 +-
 2 files changed, 32 insertions(+), 16 deletions(-)

diff --git a/external_libs/fortrancl/cl_command_queue.f90 b/external_libs/fortrancl/cl_command_queue.f90
index a7676405b4..3eaf9f5eb5 100644
--- a/external_libs/fortrancl/cl_command_queue.f90
+++ b/external_libs/fortrancl/cl_command_queue.f90
@@ -94,20 +94,7 @@ module cl_command_queue_m
   ! ----------------------------------------------------
 
   interface clEnqueueNDRangeKernel
-
-    subroutine clEnqueueNDRangeKernel_low(command_queue, kernel, dim, globalsizes, localsizes, status)
-      use cl_types_m
-
-      implicit none
-
-      type(cl_command_queue), intent(inout) :: command_queue
-      type(cl_kernel),        intent(inout) :: kernel
-      integer,                intent(in)    :: dim
-      integer(8),             intent(in)    :: globalsizes
-      integer(8),             intent(in)    :: localsizes
-      integer,                intent(out)   :: status
-    end subroutine clEnqueueNDRangeKernel_low
-
+    module procedure clEnqueueNDRangeKernel_simple
   end interface clEnqueueNDRangeKernel
 
   ! ---------------------------------------------------
@@ -143,9 +130,38 @@ contains
 
     call clcreatecommandqueue_low(context, device, properties, errcode_ret, command_queue)
 
-
   end function clCreateCommandQueue_full
 
+  subroutine clEnqueueNDRangeKernel_simple(command_queue, kernel, globalsizes, localsizes, status)
+    type(cl_command_queue), intent(inout) :: command_queue
+    type(cl_kernel),        intent(inout) :: kernel
+    integer(8),             intent(in)    :: globalsizes(:)
+    integer(8),             intent(in)    :: localsizes(:)
+    integer,                intent(out)   :: status
+
+    interface
+      subroutine clEnqueueNDRangeKernel_low(command_queue, kernel, work_dim, globalsizes, localsizes, status)
+        use cl_types_m
+
+        implicit none
+
+        type(cl_command_queue), intent(inout) :: command_queue
+        type(cl_kernel),        intent(inout) :: kernel
+        integer,                intent(in)    :: work_dim
+        integer(8),             intent(in)    :: globalsizes
+        integer(8),             intent(in)    :: localsizes
+        integer,                intent(out)   :: status
+      end subroutine clEnqueueNDRangeKernel_low
+    end interface
+
+    integer :: work_dim
+
+    work_dim = min(ubound(globalsizes, dim = 1), ubound(localsizes, dim = 1))
+
+    call clEnqueueNDRangeKernel_low(command_queue, kernel, work_dim, globalsizes(1), localsizes(1), status)
+
+  end subroutine clEnqueueNDRangeKernel_simple
+
 end module cl_command_queue_m
 
 !! Local Variables:
diff --git a/src/basic/opencl.F90 b/src/basic/opencl.F90
index 99bb44f737..111dcb32bf 100644
--- a/src/basic/opencl.F90
+++ b/src/basic/opencl.F90
@@ -733,7 +733,7 @@ module opencl_m
       gsizes(1:dim) = int(globalsizes(1:dim), 8)
       lsizes(1:dim) = int(localsizes(1:dim), 8)
 
-      call clEnqueueNDRangeKernel(opencl%command_queue, kernel, dim, gsizes(1), lsizes(1), ierr)
+      call clEnqueueNDRangeKernel(opencl%command_queue, kernel, gsizes, lsizes, ierr)
       if(ierr /= CL_SUCCESS) call opencl_print_error(ierr, "EnqueueNDRangeKernel")
 
       call profiling_out(prof_kernel_run)
-- 
GitLab