public static CudaEngine getCudaEngine(CudaObject co) {
    synchronized (cudaEngines) {
      if (!isCudaAvailable()) throw new CudaException("No cuda device found");
      try {
        initialization.awaitTermination(100, TimeUnit.SECONDS);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      Pheromone p = (Pheromone) co;
      final int pheroID = cudaObjectID.incrementAndGet();

      final CudaEngine ce = cudaEngines.get(pheroID % availableDevicesNb);
      //			final CudaEngine ce = cudaEngines.get(1);
      //			final CudaEngine ce = cudaEngines.get(0);

      //			final CudaEngine ce;
      //			if(p.getName().contains("PRE")){
      //				ce = cudaEngines.get(0);
      //			}
      //			else{
      //				ce = cudaEngines.get(1);
      //			}
      //
      ce.cudaObjects.add(co);
      System.err.println(co + "ID " + pheroID + " getting cuda engine Id " + ce.Id);
      return ce;
    }
  }
 /** Stop the executors and clean memory on registered CUObject */
 public static void stop() {
   synchronized (cudaEngines) {
     cuCtxSynchronizeAll();
     for (Iterator<CudaEngine> iterator = cudaEngines.values().iterator(); iterator.hasNext(); ) {
       iterator.next().shutdown();
       iterator.remove();
     }
     //		for (CudaEngine ce : cudaEngines.values()) {
     //			ce.shutdown();
     //		}
   }
 }
 public static synchronized void cuCtxSynchronizeAll() {
   for (CudaEngine ce : cudaEngines.values()) {
     ce.cuCtxSynchronize();
   }
   // List<Future<Void>> futures = new ArrayList<Future<Void>>();
   // for (CudaEngine ce : executors) {
   // futures.add(ce.exe.submit(new Callable<Void>() {
   // @Override
   // public Void call() throws Exception {
   // JCudaDriver.cuCtxSynchronize();
   // return null;
   // }
   //
   // }));
   // }
   // for (Future<Void> future : futures) {
   // try {
   // future.get();
   // } catch (InterruptedException | ExecutionException e) {
   // // TODO Auto-generated catch block
   // e.printStackTrace();
   // }
   // }
 }
 public void addNeighborsPtr(String string, CUdeviceptr neighborsPtr) {
   neigborsPtrs.put(string, neighborsPtr);
 }
 public CUdeviceptr getNeighborsPtr(String string) {
   return neigborsPtrs.get(string);
 }
 /** Stop the executors and clean memory on registered CUObject */
 public static synchronized void freeMemory() {
   for (CudaEngine ce : cudaEngines.values()) {
     ce.freeCUObjectsMemory();
   }
 }