Compiling CUDA-C program linked with NetCDF-4.1.3 (gcc and nvcc) – Mac OSX

Last Friday, I was working on compiling and linking a program that I have written previously, using CUDA-C, with NetCDF library. Well, may be it’s better to give some more details.

I am now in the Netherlands working on some cool stuf regarding the water study. I ported the Surface Energy Balance System (SEBS) algorithm on NVIDIA GPUs using CUDA-C. The achievement: well, on a Tesla C1060 I got something like 200 times speed-up. SEBS algorithm calculates evapotranspiration (ET). This means that the required calculation time to obtain ET over United States with 1km spatial resolution and daily temporal resolution for one year can be reduced from 11.5 days to 1 hour and 23 minutes, and you don’t need a super computer, you can get the hardware with less than $1000.00.

Well, that was a test stage. To make everything simple, I was reading the input variables simply from bunch of ASCII files. The next stage was to change the code, so it reads from NetCDF file format, (my beloved file format by the way).

But immediately, I was stopped with a problem. What was the problem? The nvcc was compiling using i386 architecture, while my NetCDF was compiled with x86_64 architecture. So, they were not linking at the end. Well, the solution: re-compile the NetCDF with i386 architecture.

I checked the NetCDF libraries architecture by typing:

file libnetcdf.dylib

I could see the x86_64 reported as the architecture. I downloaded the latest NetCDF library available at the time (v4.1.3) and configured it as follow:

sudo CC=gcc CPPFLAGS=”-g -O2 -arch i386″ CFLAGS=”-g -O2 -arch i386″ ./configure –prefix=/usr/local/netcdf_4.1.3 –disable-netcdf-4 –disable-fortran –disable-cxx

I didn’t wanted the C++ API, nor the FORTRAN’s API; because I already have them compiled in another directory. After successfully compiling the NetCDF, just type:

sudo make check install

and you are done. Nothing is needed anymore. Well, almost nothing. Just remember when you are compiling with nvcc provide “-I/usr/local/netcdf_4.1.3/include”; and when you are linking the compiled files add “-L/usr/local/netcdf_4.1.3/lib -lnetcdf” to your linker flags in the makefile.

well, now enjoy the NetCDF and CUDA-C together.

(well, All above procedure was performed on Mac OS X 10.6.8)

This entry was posted in Tech Tips. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s