Here is a sample makefile, like what I use with the Intel MPI compilers (used during PETSc configuration) and MKL library.
Matt Overholt --------------------------------------------- # # makefile for Linux using the Intel C++ Compiler, MKL & MPI libraries + OpenMP # usage: make # or: make clean # # Although explicit paths are used for all libraries and compilers below, it is # still necessary to first call the Intel scripts as follows: # if [ -z "$I_MPI_ROOT" ]; then # source /opt/intel/compilers_and_libraries/linux/mpi/intel64/bin/mpivars.sh # fi # if [ -z "$MKLROOT" ]; then # source /opt/intel/parallel_studio_xe_2018/bin/psxevars.sh intel64 # fi # Use OMP_NUM_THREADS to set # of threads ### MPI Compilers for C++ and C ### COMPILER_DIR = /opt/intel/compilers_and_libraries/linux/mpi/intel64/bin COMPILER = $(COMPILER_DIR)/mpiicpc CCOMPILER = $(COMPILER_DIR)/mpiicc ### Intel MKL & MPI libraries ### MKL_DIR = /opt/intel/compilers_and_libraries/linux/mkl MKL_INC = $(MKL_DIR)/include MKL_LIB = $(MKL_DIR)/lib/intel64 ### Compiling Flags (debug and optimized) ### # CCFLAGS = -c -O0 -g -traceback -heap-arrays -check=stack,uninit -I$(MKL_INC) -qopenmp CCFLAGS = -c -I$(MKL_INC) -qopenmp ### Linking Flags (debug and optimized) ### # CLFLAGS = -g -lstdc++ -qopenmp CLFLAGS = -lstdc++ -qopenmp ### MKL Libraries ### # Sequential threading layer # MKLFLAGS = -Wl,--start-group \ # ${MKLROOT}/lib/intel64/libmkl_intel_lp64.a \ # ${MKLROOT}/lib/intel64/libmkl_sequential.a \ # ${MKLROOT}/lib/intel64/libmkl_core.a \ # -Wl,--end-group -lpthread -lm -ldl # OpenMP parallel threading layer MKLFLAGS = -Wl,--start-group \ $(MKL_LIB)/libmkl_intel_lp64.a \ $(MKL_LIB)/libmkl_intel_thread.a \ $(MKL_LIB)/libmkl_core.a \ $(MKL_LIB)/libmkl_blacs_intelmpi_lp64.a \ -Wl,--end-group -liomp5 -lpthread -lm -ldl TARGET = myprogram ### Object Files ### OBJFILES = \ class1.o \ class2.o all: $(TARGET) # # Build (link) it $(TARGET) : $(OBJFILES) $(COMPILER) -o $(TARGET) $(OBJFILES) $(CLFLAGS) $(MKLFLAGS) echo $(TARGET) BUILT AS A 64-BIT LINUX APPLICATION! # # Compile the source files with C and CPP MPI compilers # CPP class1.o : class1.cpp $(COMPILER) $(CCFLAGS) class1.cpp # C class2.o : class2.c $(CCOMPILER) $(CCFLAGS) class2.c # main myprogram.o : myprogram.c $(CCOMPILER) $(CCFLAGS) myprogram.c # to clean up .PHONY : clean clean: -rm -f $(OBJFILES) -rm -f $(TARGET) echo myprogram cleaned --------------------------------------------- On Tue, Oct 23, 2018 at 1:46 PM Matthew Knepley <knep...@gmail.com> wrote: > On Tue, Oct 23, 2018 at 11:37 AM Yingjie Wu <yjw...@gmail.com> wrote: > >> Dear Petsc developer: >> Hi, >> Thank you very much for your continuous help, I recently encountered some >> difficulties in developing programs on Petsc. >> >> 1. I want to use my class definition (class1. h) and class functions >> (class1. cpp) files in my Petsc program (myprogram. c) and compile my >> program. I have written other program before: >> g++ -c class1.cpp myprogram.c >> g++ -o myprogram *.o >> I also have some knowledge of Makefile, but I don't know how to modify it >> to achieve compilation. I really want your help. >> > > With PETSc makefiles, we have automatic rules, so you can use > > myprogram: class1.o myprogram.o > ${CLINKER} -o myprogram class1.o myprogram.o ${PETSC_LIB} > > >> 2. In my class definition and function implementation program, I want to >> use Petsc data structures, such as PetscInt, PetscReal. In order to >> maintain consistency of the main program. What kind of header files should >> I add to my code, or do I need to add any code? >> > > The easiest thing to do is just > > #include <petsc.h> > > Thanks, > > Matt > > >> Thanks, >> Yingjie >> > > > -- > What most experimenters take for granted before they begin their > experiments is infinitely more interesting than any results to which their > experiments lead. > -- Norbert Wiener > > https://www.cse.buffalo.edu/~knepley/ > <http://www.cse.buffalo.edu/~knepley/> >