# by default some intel compilers put temporaries on the stack
# this might lead to segmentation faults is the stack limit is set to low
# stack limits can be increased by sysadmins or e.g with ulimit -s 256000
# furthermore new ifort (10.0?) compilers support the option
# -heap-arrays 64
# add this to the compilation flags is the other options do not work
# The following settings worked for:
# - AMD64 Opteron
# - SUSE Linux Enterprise Server 10.0 (x86_64)
# - Intel(R) Fortran Compiler for Intel(R) EM64T-based applications, Version 10.0
# - AMD acml library version 3.6.0
# - MPICH2-1.0.5p4
# - FFTW 3.1.2
#
PERL     = perl
CC       = gcc
CPP      = cpp
NVCC	 = /usr/local/cuda/bin/nvcc
FC       = /opt/intel/fce/10.0.025/bin/ifort -FR
LD       = /opt/intel/fce/10.0.025/bin/ifort -i-static -openmp
AR       = ar -r

DFLAGSBASE   = -D__INTEL -D__CUDAPW -D__FFTSG -D__CUBLASDP
DFLAGS   = $(DFLAGSBASE) -DDGEMM=cuda_d_gemm -Ddgemm=cuda_d_gemm -DDSYMM=gpu_d_symm -Ddsymm=gpu_d_symm 
DFLAGSCU  = $(DFLAGSBASE) -Dcpu_d_gemm=dgemm -Dcpu_d_symm=dsymm

CFLAGS   =  -O2
CPPFLAGS = -traditional -C $(DFLAGS) -P -I/opt/intel/mkl/10.0.1.014/include/fftw
CPPFLAGSCU = -traditional -C $(DFLAGSCU) -P -I/opt/intel/mkl/10.0.1.014/include/fftw
NVFLAGS	 = $(DFLAGS) -arch sm_13 -deviceemu
FCFLAGS  = $(DFLAGS) -O2 -xW 
FCFLAGSCU = $(DFLAGSCU) -O2 -xW
MKLPATH  = /opt/intel/mkl/10.0.1.014/lib/em64t/
CUDAPATH = /usr/local/cuda/lib/
LDFLAGS  = $(FCFLAGS)
LIBS     = -L$(MKLPATH)\
           $(MKLPATH)/libmkl_em64t.a\
           $(MKLPATH)/libmkl_lapack.a\
           $(MKLPATH)/libguide.a\
           $(CUDAPATH)/libcudart.so\
           $(CUDAPATH)/libcufft.so\
           $(CUDAPATH)/libcublas.so\
           /usr/local/lib/libfftw3f.a\
           -lpthread


cuda_cublas.o: cuda_cublas.F
	$(CPP) $(CPPFLAGSCU) $< > cuda_cublas.f90
	$(FC) -c $(FCFLAGSCU) cuda_cublas.f90

