  * @param commSize - the size of MPI comm world
  */
 
-#ifdef HAVE_MPI         
 /// Note that this function was lifted from http://code.google.com/p/gpmr/
 void setDevice(int commRank, int commSize)
 {
+    int devCount;
+    int deviceNum=0;
+    CUDA_CHECK(cudaGetDeviceCount(&devCount));
+#ifdef HAVE_MPI  
     FILE * fp = popen("/bin/hostname", "r");
     char buf[1024];
     if (fgets(buf, 1023, fp) == NULL) strcpy(buf, "localhost");

        MPI_Send(&devCount, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
        MPI_Recv(&deviceNum, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &stat);
    }
    CUDA_CHECK(cudaSetDevice(deviceNum));
    MPI_Barrier(MPI_COMM_WORLD);
}
#endif

/** One epoch on the GPU, dense variant
 */

                printf("Error, more jobs running on '%s' than devices - %d jobs > %d devices.\n",
                       it->first.c_str(), static_cast<int>(it->second.size()), devCounts[it->first]);
                fflush(stdout);
                my_abort(1);
            }
        }

