Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed lblas issue with null pointers #80

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
251 changes: 251 additions & 0 deletions MakefileHPC
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
# to find path to openmpi, type mpiexec --test , the error messege reveals path
MKL_HOME = /apps/cent7/intel/compilers_and_libraries_2017.1.132/linux/mkl
BROWN_MPI_HOME = /apps/brown/openmpi/2.1.0/gcc-5.2.0
SNYDER_MPI_HOME = /apps/snyder7/openmpi/2.1.0_gcc-5.2.0
MPI_HOME = $(SNYDER_MPI_HOME)

BLAS_LIB = -L$(MKL_HOME)/lib/intel64 -Wl,-rpath=$(MKL_HOME)/lib/intel64 -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp
LAPACK_LIB = -L$(MKL_HOME)/lib/intel64 -Wl,-rpath=$(MKL_HOME)/lib/intel64 -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core

EXTRA_FLAGS = '-Wl,-rpath=$(MKL_HOME)/lib/intel64' , '-Wl,-rpath=$(MPI_HOME)/lib'

EXTRA_DIRS = '$(MKL_HOME)/lib/intel64' , '$(MPI_HOME)/lib'

#BLAS_LIB = -lblas
#LAPACK_LIB = -llapack

# OPTIONAL
# Typically if installed,
# FFTW3_INC can be left empty
# FFTW3_LIB = -lfftw3
# or, if Fedora and/or fftw is version 3 but named fftw rather than fftw3
# FTW3_LIB = -lfftw
# May need to link libraries properly as with blas and lapack above
FFTW3_INC = -I$(MLK_HOME)/include/fftw/
FFTW3_LIB = $(BLAS_LIB)

# Typically,
# PTHREAD_INC = -DHAVE_UNISTD_H
# PTHREAD_LIB = -lpthread
PTHREAD_INC = -DHAVE_UNISTD_H
PTHREAD_LIB = -lpthread

# OPTIONAL
# If not installed:
# Fedora: dnf install libsuitsparse-devel
# Typically, if installed:
#CHOLMOD_INC = -I/usr/include/suitesparse
#CHOLMOD_LIB = -lcholmod -lamd -lcolamd -lcamd -lccolamd
#CHOLMOD_INC = -I/usr/include/suitesparse
#CHOLMOD_LIB = -lcholmod -lamd -lcolamd -lcamd -lccolamd

# Specify the MPI library
# For example, on Fedora: dnf install openmpi-devel
#MPI_INC = -I/usr/include/openmpi-x86_64/openmpi/ompi
#MPI_LIB = -lmpi
# or, explicitly link to the library with -L, example below
MPI_LIB = -L$(MPI_HOME)/lib -Wl,-rpath=$(MPI_HOME)/lib -lmpi
MPI_INC = -I$(MPI_HOME)/include
#MPI_LIB = -L/usr/lib64/openmpi/lib/libmpi.so

# Specify custom compilers if needed
CXX = $(MPI_HOME)/bin/mpic++
CC = $(MPI_HOME)/bin/mpicc

#CFLAGS += -O3 -fPIC
CFLAGS = -O3 -msse3 -msse2 -msse -fPIC

# options for Sampler module
OPTFLAGS = -O3

OBJDIR = ./build
S4_BINNAME = $(OBJDIR)/S4
S4_LIBNAME = $(OBJDIR)/libS4.a
S4r_LIBNAME = $(OBJDIR)/libS4r.a

##################### DO NOT EDIT BELOW THIS LINE #####################

#### Set the compilation flags

CPPFLAGS = -I. -IS4 -IS4/RNP -IS4/kiss_fft

ifdef BLAS_LIB
CPPFLAGS += -DHAVE_BLAS
endif

ifdef LAPACK_LIB
CPPFLAGS += -DHAVE_LAPACK
endif

ifdef FFTW3_LIB
CPPFLAGS += -DHAVE_FFTW3 $(FFTW3_INC)
endif

ifdef PTHREAD_LIB
CPPFLAGS += -DHAVE_LIBPTHREAD $(PTHREAD_INC)
endif

ifdef CHOLMOD_LIB
CPPFLAGS += -DHAVE_LIBCHOLMOD $(CHOLMOD_INC)
endif

ifdef MPI_LIB
CPPFLAGS += -DHAVE_MPI $(MPI_INC)
endif

LIBS = $(BLAS_LIB) $(LAPACK_LIB) $(FFTW3_LIB) $(PTHREAD_LIB) $(CHOLMOD_LIB) $(MPI_LIB)

#### Compilation targets

all: $(S4_LIBNAME)

objdir:
mkdir -p $(OBJDIR)
mkdir -p $(OBJDIR)/S4k
mkdir -p $(OBJDIR)/S4r
mkdir -p $(OBJDIR)/modules

S4_LIBOBJS = \
$(OBJDIR)/S4k/S4.o \
$(OBJDIR)/S4k/rcwa.o \
$(OBJDIR)/S4k/fmm_common.o \
$(OBJDIR)/S4k/fmm_FFT.o \
$(OBJDIR)/S4k/fmm_kottke.o \
$(OBJDIR)/S4k/fmm_closed.o \
$(OBJDIR)/S4k/fmm_PolBasisNV.o \
$(OBJDIR)/S4k/fmm_PolBasisVL.o \
$(OBJDIR)/S4k/fmm_PolBasisJones.o \
$(OBJDIR)/S4k/fmm_experimental.o \
$(OBJDIR)/S4k/fft_iface.o \
$(OBJDIR)/S4k/pattern.o \
$(OBJDIR)/S4k/intersection.o \
$(OBJDIR)/S4k/predicates.o \
$(OBJDIR)/S4k/numalloc.o \
$(OBJDIR)/S4k/gsel.o \
$(OBJDIR)/S4k/sort.o \
$(OBJDIR)/S4k/kiss_fft.o \
$(OBJDIR)/S4k/kiss_fftnd.o \
$(OBJDIR)/S4k/SpectrumSampler.o \
$(OBJDIR)/S4k/cubature.o \
$(OBJDIR)/S4k/Interpolator.o \
$(OBJDIR)/S4k/convert.o

S4r_LIBOBJS = \
$(OBJDIR)/S4r/Material.o \
$(OBJDIR)/S4r/LatticeGridRect.o \
$(OBJDIR)/S4r/LatticeGridArb.o \
$(OBJDIR)/S4r/POFF2Mesh.o \
$(OBJDIR)/S4r/PeriodicMesh.o \
$(OBJDIR)/S4r/Shape.o \
$(OBJDIR)/S4r/Simulation.o \
$(OBJDIR)/S4r/Layer.o \
$(OBJDIR)/S4r/Pseudoinverse.o \
$(OBJDIR)/S4r/Eigensystems.o \
$(OBJDIR)/S4r/IRA.o \
$(OBJDIR)/S4r/intersection.o \
$(OBJDIR)/S4r/predicates.o \
$(OBJDIR)/S4r/periodic_off2.o

ifndef LAPACK_LIB
S4_LIBOBJS += $(OBJDIR)/S4k/Eigensystems.o
endif

$(S4_LIBNAME): objdir $(S4_LIBOBJS)
$(AR) crvs $@ $(S4_LIBOBJS)
$(S4r_LIBNAME): objdir $(S4r_LIBOBJS)
$(AR) crvs $@ $(S4r_LIBOBJS)

$(OBJDIR)/S4k/S4.o: S4/S4.cpp
$(CXX) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(OBJDIR)/S4k/rcwa.o: S4/rcwa.cpp
$(CXX) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(OBJDIR)/S4k/fmm_common.o: S4/fmm/fmm_common.cpp
$(CXX) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(OBJDIR)/S4k/fmm_FFT.o: S4/fmm/fmm_FFT.cpp
$(CXX) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(OBJDIR)/S4k/fmm_kottke.o: S4/fmm/fmm_kottke.cpp
$(CXX) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(OBJDIR)/S4k/fmm_closed.o: S4/fmm/fmm_closed.cpp
$(CXX) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(OBJDIR)/S4k/fmm_PolBasisNV.o: S4/fmm/fmm_PolBasisNV.cpp
$(CXX) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(OBJDIR)/S4k/fmm_PolBasisVL.o: S4/fmm/fmm_PolBasisVL.cpp
$(CXX) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(OBJDIR)/S4k/fmm_PolBasisJones.o: S4/fmm/fmm_PolBasisJones.cpp
$(CXX) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(OBJDIR)/S4k/fmm_experimental.o: S4/fmm/fmm_experimental.cpp
$(CXX) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(OBJDIR)/S4k/fft_iface.o: S4/fmm/fft_iface.cpp
$(CXX) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(OBJDIR)/S4k/pattern.o: S4/pattern/pattern.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(OBJDIR)/S4k/intersection.o: S4/pattern/intersection.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(OBJDIR)/S4k/predicates.o: S4/pattern/predicates.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(OBJDIR)/S4k/numalloc.o: S4/numalloc.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(OBJDIR)/S4k/gsel.o: S4/gsel.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(OBJDIR)/S4k/sort.o: S4/sort.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(OBJDIR)/S4k/kiss_fft.o: S4/kiss_fft/kiss_fft.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(OBJDIR)/S4k/kiss_fftnd.o: S4/kiss_fft/tools/kiss_fftnd.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(OBJDIR)/S4k/SpectrumSampler.o: S4/SpectrumSampler.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(OBJDIR)/S4k/cubature.o: S4/cubature.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(OBJDIR)/S4k/Interpolator.o: S4/Interpolator.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(OBJDIR)/S4k/convert.o: S4/convert.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(OBJDIR)/S4k/Eigensystems.o: S4/RNP/Eigensystems.cpp
$(CXX) -c $(CFLAGS) $(CPPFLAGS) $< -o $@


$(OBJDIR)/S4r/Material.o: S4r/Material.cpp S4r/Material.hpp S4r/Types.hpp
$(CXX) -c $(CFLAGS) $(CPPFLAGS) -I. $< -o $@
$(OBJDIR)/S4r/LatticeGridRect.o: S4r/LatticeGridRect.cpp S4r/PeriodicMesh.hpp S4r/Types.hpp
$(CXX) -c $(CFLAGS) $(CPPFLAGS) -I. $< -o $@
$(OBJDIR)/S4r/LatticeGridArb.o: S4r/LatticeGridArb.cpp S4r/PeriodicMesh.hpp S4r/Types.hpp
$(CXX) -c $(CFLAGS) $(CPPFLAGS) -I. $< -o $@
$(OBJDIR)/S4r/POFF2Mesh.o: S4r/POFF2Mesh.cpp S4r/PeriodicMesh.hpp S4r/Types.hpp
$(CXX) -c $(CFLAGS) $(CPPFLAGS) -I. $< -o $@
$(OBJDIR)/S4r/PeriodicMesh.o: S4r/PeriodicMesh.cpp S4r/PeriodicMesh.hpp S4r/Types.hpp
$(CXX) -c $(CFLAGS) $(CPPFLAGS) -I. $< -o $@
$(OBJDIR)/S4r/Shape.o: S4r/Shape.cpp S4r/Shape.hpp S4r/Types.hpp
$(CXX) -c $(CFLAGS) $(CPPFLAGS) -I. $< -o $@
$(OBJDIR)/S4r/Simulation.o: S4r/Simulation.cpp S4r/Simulation.hpp S4r/StarProduct.hpp S4r/Types.hpp
$(CXX) -c $(CFLAGS) $(CPPFLAGS) -I. $< -o $@
$(OBJDIR)/S4r/Layer.o: S4r/Layer.cpp S4r/Layer.hpp S4r/Types.hpp
$(CXX) -c $(CFLAGS) $(CPPFLAGS) -I. $< -o $@
$(OBJDIR)/S4r/Pseudoinverse.o: S4r/Pseudoinverse.cpp S4r/Pseudoinverse.hpp S4r/Types.hpp
$(CXX) -c $(CFLAGS) $(CPPFLAGS) -I. $< -o $@
$(OBJDIR)/S4r/Eigensystems.o: S4r/Eigensystems.cpp S4r/Eigensystems.hpp S4r/Types.hpp
$(CXX) -c $(CFLAGS) $(CPPFLAGS) -I. $< -o $@
$(OBJDIR)/S4r/IRA.o: S4r/IRA.cpp S4r/IRA.hpp S4r/Types.hpp
$(CXX) -c $(CFLAGS) $(CPPFLAGS) -I. $< -o $@
$(OBJDIR)/S4r/intersection.o: S4r/intersection.c S4r/intersection.h
$(CC) -c -O3 $< -o $@
$(OBJDIR)/S4r/periodic_off2.o: S4r/periodic_off2.c S4r/periodic_off2.h
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
$(OBJDIR)/S4r/predicates.o: S4r/predicates.c
$(CC) -c -O3 $< -o $@

#### Python extension

check:
@echo $(LIBS)

S4_pyext: objdir $(S4_LIBNAME)
echo "Linking...."
echo $(EXTRA_FLAGS) $(EXTRA_DIRS)
sh gensetupHPC.py.sh $(OBJDIR) $(S4_LIBNAME) "$(LIBS)" "$(EXTRA_FLAGS)" "$(EXTRA_DIRS)"
python setup.py build
#pip3 install --upgrade ./

clean:
rm S4.so
rm -rf $(OBJDIR)
122 changes: 122 additions & 0 deletions PythonTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@

# all lengths normalized in terms of a
# frequency normalized in terms of 2*pi*c/a

# this test file plots a frequency spectrum and field plot for the python extension

import S4
import numpy as np
import matplotlib.pyplot as plt

a = 1e-6; #1nm
c_const = 3e8;
print('Bontempi, Kivshar et al. \"Highly sensitive biosensors based on all-dielectric nanoresonator\"')
p = 0.96
d = 0.73
h = 0.22
period = [p,p]
S = S4.New(Lattice=((period[0],0),(0,period[1])),NumBasis=20)
S.SetMaterial(Name = 'SiO2',Epsilon = (1.45 + 0.0j)**2)
S.SetMaterial(Name = 'Si',Epsilon = (3.487+0.0j)**2)
S.SetMaterial(Name = 'Vacuum',Epsilon = (1 + 0j)**2)

S.AddLayer(Name = 'AirAbove',Thickness = 0, Material = 'Vacuum')
S.AddLayer(Name = 'AirDisp',Thickness = 1, Material = 'Vacuum')
S.AddLayer(Name = 'Si_disks',Thickness = h,Material = 'Vacuum')

S.SetRegionCircle(
Layer = 'Si_disks',
Material = 'Si',
Center = (0,0),
Radius = d/2
)

S.AddLayer(Name = 'Glass_Below',Thickness = 2, Material = 'SiO2')
#S.AddLayerCopy(Name = 'AirBelow',Thickness = 0, Layer = 'AirAbove')
S.AddLayer(Name = 'AirBelow',Thickness = 0,Material = 'Vacuum')

S.SetExcitationPlanewave(
IncidenceAngles=(
0,# polar angle in [0,180)
0 # azimuthal angle in [0,360)
),
sAmplitude = 0,
pAmplitude = 1,
Order = 0
)

S.SetOptions(
PolarizationDecomposition = True
)

wavelength_um = float(wavelength_p_nm)/1000; # [8.0,14.0]
freq = 1 / float(wavelength_um);
S.SetFrequency(freq) #unit 2*pi*c_const / a
forward,backward = S.GetPowerFlux(Layer = 'AirAbove', zOffset = 0) # reflected power
forward = S.GetPowerFlux(Layer = 'AirBelow',zOffset = 0)
print('f='+str(1/freq)+', Power_forward= '+str(forward[0].real)+', Power_backward='+str(backward.real))

# get fields at points




# frequency sweep
wavelength_space = np.linspace(1.3, 1.7, 200)

R = wavelength_space * 0
T=R
i=0
for lam in wavelength_space:
f = 1 / float(lam)
S.SetFrequency(f)
(forw,back) = S.GetPowerFlux(Layer = 'AirAbove', zOffset = 0)
forw = S.GetPowerFlux(Layer = 'AirBelow', zOffset = 0)
R[i] = np.abs(forw[0])
#T[i] = np.abs(back)
i +=1

plt.plot(wavelength_space, R)
#plt.hold
#plt.plot(wavelength_space, T)
plt.xlabel('Wavelength (um)')
plt.ylabel('T')
plt.title('Figure 3(a)')

#field map

wavelength_p_nm = 1400;
wavelength_um = float(wavelength_p_nm)/1000; # [8.0,14.0]
freq = 1 / float(wavelength_um);
S.SetFrequency(freq) #unit 2*pi*c_const / a
x_space = np.linspace(-p/2,p/2,300)
z_space = np.linspace(0.8,1.4,300)

X,Z = np.meshgrid(x_space,z_space)
Ey = np.zeros((X.shape[0], X.shape[1]))
xc = 0
zc = 0

for x in x_space:
zc=0
#print('x='+str(x)+'\n')
for z in z_space:
#print('z='+str(z)+'\tzc='+str(zc)+'\n')
E,H = S.GetFields(x,0,z)
Ey[zc,xc] = np.abs(H[1]) ** 2 + np.abs(H[2]) ** 2 + np.abs(H[0]) ** 2
#print(str(x)+'\t'+str(z)+'\t'+str(abs(E[1])))
zc += 1
xc += 1

fig = plt.figure()
cm = np.linspace(np.min(Ey),np.max(Ey), 100)
plt.contourf(x_space, z_space, Ey, cm)
plt.plot([-p/2, p/2], [1, 1], color='w', linestyle='-', linewidth=2)
plt.plot([-d/2, d/2], [1+h, 1+h], color='w', linestyle='-', linewidth=2)
plt.plot([-d/2, -d/2], [1, 1+h], color='w', linestyle='-', linewidth=2)
plt.plot([d/2, d/2], [1, 1+h], color='w', linestyle='-', linewidth=2)
plt.title('Figure 3(c) - |H|^2 - lam = ' + str(wavelength_p_nm))
plt.show(block=True)


print('If you can read this, the configuration work is finished!')
11 changes: 11 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,14 @@ See the S4 manual, in doc/index.html, for a complete
description of the package and its user interface, as well as
installation instructions, the license and copyright, contact
addresses, and other important information.

Sajidmc:
This fork focuses on HPC compilation, especially on Purdue University clusters.
We are only using the python extension.

Note: you must edit the MakefileHPC and manually check/add the paths to each of the libraries

Usage:

make -f MakefileHPC clean
make -f MakefileHPC S4_pyext
Loading