From eb7e7f6d9611d4c3547f829a6e0bb525f065ae7b Mon Sep 17 00:00:00 2001
From: James Wilson <wilsja@wirelessprv-10-192-250-37.near.illinois.edu>
Date: Fri, 11 Nov 2016 15:24:29 -0600
Subject: [PATCH] Made code compile on OSX

---
 src/BaseGrid.h             |  4 ++--
 src/BrownianParticleType.h |  1 -
 src/ComputeForce.h         |  2 +-
 src/DcdWriter.h            |  2 +-
 src/FlowForce.h            |  2 +-
 src/GrandBrownTown.h       |  2 +-
 src/Makefile               | 12 +++++++++---
 src/RandomCUDA.cu          |  2 +-
 src/RigidBodyGrid.h        |  2 +-
 src/Scatter.h              |  2 +-
 src/arbd.cpp               |  3 ++-
 src/findcudalib.mk         | 10 ++++------
 src/gridSampleDef.c        |  2 +-
 src/gridSampleFlow.c       |  2 +-
 src/useful.h               |  4 ++--
 15 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/src/BaseGrid.h b/src/BaseGrid.h
index 73d48f1..eee5cf7 100644
--- a/src/BaseGrid.h
+++ b/src/BaseGrid.h
@@ -19,10 +19,10 @@
 #include <cstdio>
 #include <cstdlib>
 #include <ctime>
-#include <cuda.h>
+// #include <cuda.h>
 
 
-using namespace std;
+// using namespace std;
 
 #define STRLEN 512
 
diff --git a/src/BrownianParticleType.h b/src/BrownianParticleType.h
index a3c5f48..b6ed4ec 100644
--- a/src/BrownianParticleType.h
+++ b/src/BrownianParticleType.h
@@ -13,7 +13,6 @@
 #include "Reservoir.h"
 #include "BaseGrid.h"
 #include "CellDecomposition.h"
-#include "BaseGrid.h"
 
 // Stores particle type's potential grid and other information
 class BrownianParticleType {
diff --git a/src/ComputeForce.h b/src/ComputeForce.h
index 66d6e75..cbe2be8 100644
--- a/src/ComputeForce.h
+++ b/src/ComputeForce.h
@@ -24,7 +24,7 @@
 #include "TabulatedDihedral.h"
 
 #include <cstdio>
-#include <cuda.h>
+// #include <cuda_runtime.h>
 #include <thrust/transform_reduce.h>	// thrust::reduce
 #include <thrust/functional.h>				// thrust::plus
 
diff --git a/src/DcdWriter.h b/src/DcdWriter.h
index f2c0f61..d5ab57d 100644
--- a/src/DcdWriter.h
+++ b/src/DcdWriter.h
@@ -21,7 +21,7 @@
 #include <fcntl.h>
 #include <sys/stat.h>
 
-using namespace std;
+// using namespace std;
 
 #define NFILE_POS (off_t) 8
 #define NPRIV_POS (off_t) 12
diff --git a/src/FlowForce.h b/src/FlowForce.h
index 870aca0..8ffe930 100644
--- a/src/FlowForce.h
+++ b/src/FlowForce.h
@@ -5,7 +5,7 @@
 
 #include <cmath>
 #include "useful.h"
-using namespace std;
+// using namespace std;
 
 class FlowForce {
 public:
diff --git a/src/GrandBrownTown.h b/src/GrandBrownTown.h
index 006ae8a..9810664 100644
--- a/src/GrandBrownTown.h
+++ b/src/GrandBrownTown.h
@@ -48,7 +48,7 @@
 
 //#include "analyticForce.h"
 
-using namespace std;
+// using namespace std;
 
 // #define FORCEGRIDOFF
 
diff --git a/src/Makefile b/src/Makefile
index b8da44f..f359fd0 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -2,7 +2,6 @@
 include ./findcudalib.mk
 INCLUDE = $(CUDA_PATH)/include
 
-NV_FLAGS += v
 ifeq ($(dbg),1)
 	CC_FLAGS += -g -O0
 	NV_FLAGS += -g -G
@@ -11,7 +10,8 @@ else
 	EX_FLAGS = -O3 -m$(OS_SIZE)
 endif
 
-CC_FLAGS += -Wall -Wno-write-strings -I$(INCLUDE) -std=c++0x -pedantic
+CC_FLAGS += -I$(CUDA_PATH)/include
+# CC_FLAGS += -Wall -Wno-write-strings -std=c++0x -pedantic
 NV_FLAGS += -lineinfo
 
 ifneq ($(DARWIN),)
@@ -22,10 +22,16 @@ endif
 
 # NV_FLAGS += -ftz=true			# TODO: test if this preserves accurate simulation
 
+$(info $(NVCC))
+
 ## Find valid compute capabilities for this machine
 SMS ?= 20 30 35 37 50 52 60
 $(info Testing CUDA toolkit with compute capabilities SMS='$(SMS)')
-SMS := $(shell for sm in $(SMS); do $(NVCC) cuda-test.c -arch=sm_$$sm &> /dev/null && echo $$sm; done)
+SMS := $(shell for sm in $(SMS); do $(NVCC) cuda-test.c -arch=sm_$$sm -o /dev/null &> /dev/null && echo $$sm; done)
+
+ifeq (,$(SMS))
+    $(error nvcc ($(NVCC)) failed with all tested compute capabilities.)
+endif
 
 SMPTXS ?= $(lastword $(sort $(SMS)))
 $(info Building SASS code for SMS='$(SMS)' and PTX code for '$(SMPTXS)')
diff --git a/src/RandomCUDA.cu b/src/RandomCUDA.cu
index 6700280..0a92583 100644
--- a/src/RandomCUDA.cu
+++ b/src/RandomCUDA.cu
@@ -79,7 +79,7 @@ void Random::reorder(int a[], int n) {
 		unsigned int j = i + (integer() % (n-i));
 		if ( j == i )
 			continue;
-		swap<int>(a[i], a[j]);
+		std::swap<int>(a[i], a[j]);
 		const int tmp = a[j];
 		a[j] = a[i];
 		a[i] = tmp;
diff --git a/src/RigidBodyGrid.h b/src/RigidBodyGrid.h
index 2c46b4f..96a5d03 100644
--- a/src/RigidBodyGrid.h
+++ b/src/RigidBodyGrid.h
@@ -22,7 +22,7 @@
 #include <ctime>
 #include <cuda.h>
 
-using namespace std;
+// using namespace std;
 
 #define STRLEN 512
 
diff --git a/src/Scatter.h b/src/Scatter.h
index b6bee35..3347fcc 100644
--- a/src/Scatter.h
+++ b/src/Scatter.h
@@ -8,7 +8,7 @@
 #include <cstdlib>
 #include <cstdio>
 #include "useful.h"
-using namespace std;
+// using namespace std;
 
 class Scatter {
 public:
diff --git a/src/arbd.cpp b/src/arbd.cpp
index ebd1eea..32bcccd 100644
--- a/src/arbd.cpp
+++ b/src/arbd.cpp
@@ -9,7 +9,8 @@
 #include "Configuration.h"
 #include "GPUManager.h"
 
-using namespace std;
+// using namespace std;
+using std::max;
 
 const unsigned int kIMDPort = 71992;
 
diff --git a/src/findcudalib.mk b/src/findcudalib.mk
index 7c78849..4694c94 100644
--- a/src/findcudalib.mk
+++ b/src/findcudalib.mk
@@ -36,13 +36,11 @@
 
 ## Find Location of most recent CUDA Toolkit
 ifeq (,$(CUDA_PATH))
-	CUDA_PATH := $(shell echo $(wildcard /usr/local/cuda*) | tr ' ' '\n' | sort -Vr | head -n1)
+    CUDA_PATH := $(shell echo $(wildcard /usr/local/cuda*) | tail -n1)
     ifeq (,$(CUDA_PATH))
-        $(info ERROR: Could not CUDA_PATH. Please pass as follows: $(MAKE) CUDA_PATH=/path/to/cuda)
-        exit
-    else 
-        $(info Using CUDA_PATH=$(CUDA_PATH))
+        $(error Could not CUDA_PATH. Please pass as follows: $(MAKE) CUDA_PATH=/path/to/cuda)
     endif
+    $(info Using CUDA_PATH=$(CUDA_PATH))
 endif
 
 # OS Name (Linux or Darwin)
@@ -91,7 +89,7 @@ else
     ifeq ($(shell expr `xcodebuild -version | grep -i xcode | awk '{print $$2}' | cut -d'.' -f1` \>= 5),1)
         CC = $(CLANG)
 		CC_FLAGS += -stdlib=libstdc++
-		NV_FLAGS += -Xcompiler -arch -Xcompiler x86_64
+		NV_FLAGS += -Xcompiler -arch -Xcompiler x86_64 -Xcompiler -stdlib=libstdc++
     endif
 endif
 NVCC ?= $(CUDA_PATH)/bin/nvcc -ccbin $(CC)
diff --git a/src/gridSampleDef.c b/src/gridSampleDef.c
index e5082f2..c89bec5 100644
--- a/src/gridSampleDef.c
+++ b/src/gridSampleDef.c
@@ -8,7 +8,7 @@
 #include "BaseGrid.h"
 #include "OverlordGrid.h"
 
-using namespace std;
+//using namespace std;
 
 int main(int argc, char* argv[]) {
   if ( argc != 4 ) {
diff --git a/src/gridSampleFlow.c b/src/gridSampleFlow.c
index b7a94d3..f5f2896 100644
--- a/src/gridSampleFlow.c
+++ b/src/gridSampleFlow.c
@@ -8,7 +8,7 @@
 #include "BaseGrid.h"
 #include "FlowForce.h"
 
-using namespace std;
+// using namespace std;
 
 int main(int argc, char* argv[]) {
   if ( argc != 4 ) {
diff --git a/src/useful.h b/src/useful.h
index 73f1b7b..1618b9a 100644
--- a/src/useful.h
+++ b/src/useful.h
@@ -16,9 +16,9 @@
 #include <cstring>
 #include <cstdio>
 #include <cstdlib>
-#include <cuda.h>
+//#include <cuda_runtime.h>
 
-using namespace std;
+// using namespace std;
 
 bool isReal(char c);
 
-- 
GitLab