Index: BLAS/xGEMM/Makefile
===================================================================
--- BLAS/xGEMM/Makefile	(revision 52)
+++ BLAS/xGEMM/Makefile	(revision 53)
@@ -1,16 +1,18 @@
 SOURCE=xGEMM.c
 
-CC=gcc-4.6
-FC=gfortran-4.6
-CFLAGS=-Wall -O3
+CC=gcc-4.7
+FC=gfortran-4.7
+CFLAGS=-Wall -O3 -ffast-math
 LDFLAGS=-lm
 CUDASRC=/usr/share/doc/nvidia-cuda-doc/examples/
 THUNKING=fortran_thunking.c
 CUDASRCINC=fortran_common.h
 CUDAINC=/usr/include
 CUDALIB=/usr/lib/x86_64-linux-gnu/
-CLBLASINC=/opt/clBLAS/build/include
-CLBLASLIB=/opt/clBLAS/build/library/
+# CLBLASINC=/opt/clBLAS/build/include
+# CLBLASLIB=/opt/clBLAS/build/library/
+CLBLASINC=/opt/clBLAS/src
+CLBLASLIB=/opt/clBLAS/src/library/
 
 PATCHTHUNKING=patch_thunking.h
 
Index: BLAS/xGEMM/xGEMM.c
===================================================================
--- BLAS/xGEMM/xGEMM.c	(revision 52)
+++ BLAS/xGEMM/xGEMM.c	(revision 53)
@@ -15,6 +15,9 @@
 
 #ifdef CLBLAS
 #include <clBLAS.h>
+/* Precise here to avoid new specific bench function */
+int MyPlatform;
+int MyDevice;
 #elif CUBLAS
 #include <cublas.h>
 #define CUBLAS_WRAPPER_ERROR_NOERR      0
@@ -237,29 +240,55 @@
   /* Compute with CLBLAS library  */
 #ifdef CLBLAS
 
+  cl_uint platformCount;
+  cl_platform_id* platforms;
+  cl_uint deviceCount;
+  cl_device_id* devices;
+
   cl_int err,errA,errB,errC,errD;
-  cl_platform_id platform = 0;
-  cl_device_id device = 0;
   cl_context_properties props[3] = { CL_CONTEXT_PLATFORM, 0, 0 };
   cl_context ctx = 0;
   cl_command_queue queue = 0;
   cl_mem bufA, bufB, bufC, bufD;
   cl_event event = NULL;
 
+  char* value;
+  size_t valueSize;
+
+  // tv3 Put on Device: Allocate & Write buffer
+  // tv4 Compute
   struct timeval tv3,tv4;
 
-  printf("Using CLBLAS: %i iterations for %ix%i matrix\n",
-	 RUNS,dim,dim);
+  printf("Using CLBLAS: %i iterations for %ix%i matrix on (%d,%d)\n",
+	 RUNS,dim,dim,MyPlatform,MyDevice);
 
   /* Setup OpenCL environment. */
-  /* EQ : Select GPU on 0. Generic version to be performed */
-  err = clGetPlatformIDs( 1, &platform, NULL );
-  err = clGetDeviceIDs( platform, CL_DEVICE_TYPE_GPU, 1, &device, NULL );
-  
-  props[1] = (cl_context_properties)platform;
-  ctx = clCreateContext( props, 1, &device, NULL, NULL, &err );
-  queue = clCreateCommandQueue( ctx, device, 0, &err );
+  /* - get all platforms and select MyPlatform */
+  /* - get all devices from MyPlatform and select MyDevice */
 
+  // Get all platforms
+  err = clGetPlatformIDs(0, NULL, &platformCount);
+  platforms = (cl_platform_id*) malloc(sizeof(cl_platform_id) * platformCount);
+  err = clGetPlatformIDs(platformCount, platforms, NULL);
+
+  // Get Device defined
+  err = clGetDeviceIDs(platforms[MyPlatform], CL_DEVICE_TYPE_ALL, 0, NULL, &deviceCount);
+  devices = (cl_device_id*) malloc(sizeof(cl_device_id) * deviceCount);
+  err = clGetDeviceIDs(platforms[MyPlatform], CL_DEVICE_TYPE_ALL, deviceCount, devices, NULL);  
+
+  // print device name
+  err = clGetDeviceInfo(devices[MyDevice], CL_DEVICE_NAME, 0, NULL, &valueSize);
+  value = (char*) malloc(valueSize);
+  err = clGetDeviceInfo(devices[MyDevice], CL_DEVICE_NAME, valueSize, value, NULL);
+  printf("Device (%d,%d): %s\n",MyPlatform,MyDevice, value);
+  free(value);
+
+  props[1] = (cl_context_properties)platforms[MyPlatform];
+
+  /* Initialize Context */
+  ctx = clCreateContext( props, 1, &devices[MyDevice], NULL, NULL, &err );
+  queue = clCreateCommandQueue( ctx, devices[MyDevice], 0, &err );
+
   /* Setup clBLAS */
   err = clblasSetup( );
 
@@ -295,6 +324,10 @@
 
     }
   
+  if (err != CL_SUCCESS) {
+    printf("clblasDgemm() failed with %d\n", err);
+  }
+
 #else
 
   for (i=0;i<RUNS;i++)
@@ -309,17 +342,24 @@
 			 bufD,0,dim,1,&queue,0,NULL,&event );
     }
   
+  if (err != CL_SUCCESS) {
+    printf("clblasSgemm() failed with %d\n", err);
+  }
+
 #endif
 
   /* Wait for calculations to be finished. */
   err = clWaitForEvents( 1, &event );
   
+  /* Get fourth timer after memory free */
+  gettimeofday(&tv4, &tz);
+
   /* Fetch results of calculations from GPU memory. */
-  err = clEnqueueReadBuffer( queue,bufC,CL_TRUE,0,dim*dim * sizeof(*C),
+  errC = clEnqueueReadBuffer( queue,bufC,CL_TRUE,0,dim*dim * sizeof(*C),
 			     C,0,NULL,NULL );
 
   /* Fetch results of calculations from GPU memory. */
-  err = clEnqueueReadBuffer( queue,bufD,CL_TRUE,0,dim*dim*sizeof(*D),
+  errD = clEnqueueReadBuffer( queue,bufD,CL_TRUE,0,dim*dim*sizeof(*D),
 			     D,0,NULL,NULL );
 
   /* Release OpenCL memory objects. */
@@ -335,8 +375,6 @@
   clReleaseCommandQueue( queue );
   clReleaseContext( ctx );
   
-  /* Get fourth timer after memory free */
-  gettimeofday(&tv4, &tz);
 
   /* Compute with CuBLAS library  */
 #elif CUBLAS
@@ -413,6 +451,9 @@
   stat3=cublasGetMatrix(dim,dim,sizeof(C[0]),devPtrC,dim,C,dim);
   stat4=cublasGetMatrix(dim,dim,sizeof(D[0]),devPtrD,dim,D,dim);
   
+  /* Get fourth timer before memory free */
+  gettimeofday(&tv4, &tz);
+
   cublasFree (devPtrA);
   cublasFree (devPtrB);
   cublasFree (devPtrC);
@@ -422,8 +463,6 @@
     wrapperError ("xGEMM", CUBLAS_WRAPPER_ERROR_GET);
   }
   
-  /* Get fourth timer after memory free */
-  gettimeofday(&tv4, &tz);
 
 #elif THUNKING
   
@@ -436,7 +475,6 @@
 
   for (i=0;i<RUNS;i++)
     {      
-      /* Multiply A by X as Y <- A.X */
       CUBLAS_DGEMM(&transa,&transa,
       		   &dim,&dim,&dim,&alpha,B,&dim,A,&dim,&beta,C,&dim);
       CUBLAS_DGEMM(&transb,&transb,
@@ -447,7 +485,6 @@
 
   for (i=0;i<RUNS;i++)
     {      
-      /* Multiply A by X as Y <- A.X */
       CUBLAS_SGEMM(&transa,&transa,
       		   &dim,&dim,&dim,&alpha,B,&dim,A,&dim,&beta,C,&dim);
       CUBLAS_SGEMM(&transb,&transb,
@@ -468,7 +505,6 @@
 
   for (i=0;i<RUNS;i++)
     {    
-      /* Multiply A by X as Y <- A.X */
       dgemm_(&transa,&transa,&dim,&dim,&dim,&alpha,B,&dim,A,&dim,&beta,C,&dim);
       dgemm_(&transb,&transb,&dim,&dim,&dim,&alpha,A,&dim,B,&dim,&beta,D,&dim);
     }
@@ -477,7 +513,6 @@
 
   for (i=0;i<RUNS;i++)
     {    
-      /* Multiply A by X as Y <- A.X */
       sgemm_(&transa,&transa,&dim,&dim,&dim,&alpha,B,&dim,A,&dim,&beta,C,&dim);
       sgemm_(&transb,&transb,&dim,&dim,&dim,&alpha,A,&dim,B,&dim,&beta,D,&dim);
     }
@@ -496,7 +531,6 @@
 
   for (i=0;i<RUNS;i++)
     {    
-      /* Multiply A by X as Y <- A.X */
       dgemm(transa,transa,dim,dim,dim,alpha,B,dim,A,dim,beta,C,dim);
       dgemm(transb,transb,dim,dim,dim,alpha,A,dim,B,dim,beta,D,dim);
     }
@@ -505,7 +539,6 @@
 
   for (i=0;i<RUNS;i++)
     {    
-      /* Multiply A by X as Y <- A.X */
       sgemm(transa,transa,dim,dim,dim,alpha,B,dim,A,dim,beta,C,dim);
       sgemm(transb,transb,dim,dim,dim,alpha,A,dim,B,dim,beta,D,dim);
     }
@@ -527,7 +560,6 @@
 
   for (i=0;i<RUNS;i++)
     {  
-      /* Multiply A by X as Y <- A.X */
       cblas_dgemm(CblasRowMajor,CblasNoTrans,CblasNoTrans,
 		  dim,dim,dim,alpha,A,dim,B,dim,beta,C,dim);
       cblas_dgemm(CblasRowMajor,CblasTrans,CblasTrans,
@@ -538,7 +570,6 @@
 
   for (i=0;i<RUNS;i++)
     {  
-      /* Multiply A by X as Y <- A.X */
       cblas_sgemm(CblasRowMajor,CblasNoTrans,CblasNoTrans,
 		  dim,dim,dim,alpha,A,dim,B,dim,beta,C,dim);
       cblas_sgemm(CblasRowMajor,CblasTrans,CblasTrans,
@@ -619,7 +650,7 @@
 
   putchar('\n');
 
-#ifdef CUBLAS
+#ifdef CLBLAS
   double memoryIn,memoryOut;
 
   memoryIn=(double)((tv3.tv_sec-tv1.tv_sec) * 1000000L +	\
@@ -633,6 +664,20 @@
 
   printf("Duration of memory allocation : %2.10f s\n",memoryIn);
   printf("Duration of memory free : %2.10f s\n",memoryOut);
+#elif CUBLAS
+  double memoryIn,memoryOut;
+
+  memoryIn=(double)((tv3.tv_sec-tv1.tv_sec) * 1000000L +	\
+		    (tv3.tv_usec-tv1.tv_usec))/1000000.;  
+
+  memoryOut=(double)((tv2.tv_sec-tv4.tv_sec) * 1000000L +	\
+		    (tv2.tv_usec-tv4.tv_usec))/1000000.;  
+
+  duration=(double)((tv4.tv_sec-tv3.tv_sec) * 1000000L +	\
+		    (tv4.tv_usec-tv3.tv_usec))/1000000./RUNS;  
+
+  printf("Duration of memory allocation : %2.10f s\n",memoryIn);
+  printf("Duration of memory free : %2.10f s\n",memoryOut);
 #else
   duration=(double)((tv2.tv_sec-tv1.tv_sec) * 1000000L +	\
 		    (tv2.tv_usec-tv1.tv_usec))/1000000./RUNS;  
@@ -657,19 +702,143 @@
   return 0;
 }
 
+#ifdef CLBLAS
+
+int DelectOpenCLDevices() 
+{
+  /* */
+  /* Not needed to import CL.h, already done in CLBLAS.h */
+
+  int i, j;
+  char* value;
+  size_t valueSize;
+  cl_uint platformCount;
+  cl_platform_id* platforms;
+  cl_uint deviceCount;
+  cl_device_id* devices;
+  cl_uint maxComputeUnits;
+  cl_int maxWorkGroupSize;
+  cl_int maxWorkItemSizes;
+  cl_device_type dev_type;
+
+  // get all platforms
+  clGetPlatformIDs(0, NULL, &platformCount);
+  platforms = (cl_platform_id*) malloc(sizeof(cl_platform_id) * platformCount);
+  clGetPlatformIDs(platformCount, platforms, NULL);
+
+
+  printf("OpenCL statistics: %d platform(s) detected\n\n",platformCount);
+
+  for (i = 0; i < platformCount; i++) {
+
+    // get all devices
+    clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL, &deviceCount);
+    devices = (cl_device_id*) malloc(sizeof(cl_device_id) * deviceCount);
+    clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, deviceCount, devices, NULL);
+
+    // for each device print critical attributes
+    for (j = 0; j < deviceCount; j++) {
+      
+      // print device name
+      clGetDeviceInfo(devices[j], CL_DEVICE_NAME, 0, NULL, &valueSize);
+      value = (char*) malloc(valueSize);
+      clGetDeviceInfo(devices[j], CL_DEVICE_NAME, valueSize, value, NULL);
+      printf("Device (%d,%d): %s\n",i, j, value);
+      free(value);
+
+      // print type device CPU/GPU/ACCELERATOR
+      clGetDeviceInfo(devices[j], CL_DEVICE_TYPE, sizeof(dev_type), &dev_type, NULL);
+      printf("\tDevice Type: ");
+      if(dev_type & CL_DEVICE_TYPE_GPU)
+	printf("CL_DEVICE_TYPE_GPU ");
+      if(dev_type & CL_DEVICE_TYPE_CPU)
+	printf("CL_DEVICE_TYPE_CPU ");
+      if(dev_type & CL_DEVICE_TYPE_ACCELERATOR)
+	printf("CL_DEVICE_TYPE_ACCELERATOR ");
+      if(dev_type & CL_DEVICE_TYPE_DEFAULT)
+	printf("CL_DEVICE_TYPE_DEFAULT ");
+      printf("\n");
+
+      // print device vendor
+      clGetDeviceInfo(devices[j], CL_DEVICE_VENDOR, 0, NULL, &valueSize);
+      value = (char*) malloc(valueSize);
+      clGetDeviceInfo(devices[j], CL_DEVICE_VENDOR, valueSize, value, NULL);
+      printf("\tDevice vendor: %s\n", value);
+      free(value);
+
+      // print hardware device version
+      clGetDeviceInfo(devices[j], CL_DEVICE_VERSION, 0, NULL, &valueSize);
+      value = (char*) malloc(valueSize);
+      clGetDeviceInfo(devices[j], CL_DEVICE_VERSION, valueSize, value, NULL);
+      printf("\tHardware version: %s\n", value);
+      free(value);
+
+      // print software driver version
+      clGetDeviceInfo(devices[j], CL_DRIVER_VERSION, 0, NULL, &valueSize);
+      value = (char*) malloc(valueSize);
+      clGetDeviceInfo(devices[j], CL_DRIVER_VERSION, valueSize, value, NULL);
+      printf("\tSoftware version: %s\n", value);
+      free(value);
+      
+      // print c version supported by compiler for device
+      clGetDeviceInfo(devices[j], CL_DEVICE_OPENCL_C_VERSION, 0, NULL, &valueSize);
+      value = (char*) malloc(valueSize);
+      clGetDeviceInfo(devices[j], CL_DEVICE_OPENCL_C_VERSION, valueSize, value, NULL);
+      printf("\tOpenCL C version: %s\n", value);
+      free(value);
+
+      // print parallel compute units
+      clGetDeviceInfo(devices[j], CL_DEVICE_MAX_COMPUTE_UNITS,
+		      sizeof(maxComputeUnits), &maxComputeUnits, NULL);
+      printf("\tParallel compute units: %d\n", maxComputeUnits);
+      
+      // print max work group size
+      clGetDeviceInfo(devices[j], CL_DEVICE_MAX_WORK_GROUP_SIZE,
+		      sizeof(maxWorkGroupSize), &maxWorkGroupSize, NULL);
+      printf("\tMaximum Work Group Size: %d\n", maxWorkGroupSize);
+      
+      // print max work items size
+      clGetDeviceInfo(devices[j], CL_DEVICE_MAX_WORK_ITEM_SIZES,
+		      sizeof(maxWorkItemSizes), &maxWorkItemSizes, NULL);
+      printf("\tMaximum Work Item Sizes: %d\n", maxWorkItemSizes);
+      
+    }
+    printf("\n");
+    free(devices);
+  }
+
+  free(platforms);
+  return 0;
+
+}
+#endif
+
 int main(int argc,char **argv)
 {
   if ((argc==1)||
       (strcmp(argv[1],"-h")==0)||
       (strcmp(argv[1],"--help")==0))
     {
+#ifdef CLBLAS
       printf("\nPerforms a bench using BLAS library implementation:\n\n"
 	     "\t#1 Size of square matrices \n"
+	     "\t#2 Number of iterations \n"
+	     "\t#3 OpenCL Plateform ID\n"
+	     "\t#4 OpenCL Device ID\n\n");
+      DelectOpenCLDevices();
+#else
+      printf("\nPerforms a bench using BLAS library implementation:\n\n"
+	     "\t#1 Size of square matrices \n"
 	     "\t#2 Number of iterations\n\n");
+#endif
     }
   else if ((atoi(argv[1])>=2)&&
 	   (atoi(argv[2])>=1))
     {
+#ifdef CLBLAS
+      MyPlatform=atoi(argv[3]);
+      MyDevice=atoi(argv[4]);
+#endif
       bench(atoi(argv[1]),atoi(argv[2]));
     }
 
