thanks. It works Sepideh
________________________________ From: Matthew Knepley <[email protected]> Sent: Tuesday, April 3, 2018 5:53:56 AM To: Sepideh Kavousi Cc: [email protected] Subject: Re: [petsc-users] read variables from a source file in petsc On Mon, Apr 2, 2018 at 10:52 PM, Sepideh Kavousi <[email protected]<mailto:[email protected]>> wrote: Hi all, I wrote a petsc code, and I defined my variables in a separate file, namely common.h, and common.c as following common.h: extern int i; extern int n; Notice that these declarations are inconsistent for the main file. common.c: #include <petsc.h> #include "common.h PetscScalar i; // Define i and initialize PetscScalar n; // Define n and initialize i=2.2; n=3.5; Now in my prog.c code I have: #include <petsc.h> #include <common.h> static char help[]="program main"; int main (int argc, char **argv){ PetscInitialize(&argc,&argv, (char*) 0,help); PetscPrintf(PETSC_COMM_WORLD,"i=%f!\n",a); PetscPrintf(PETSC_COMM_WORLD,"n=%f!\n",b) ; PetscFinalize(); } if my it was not using petsc and it was a normal c code, I could run it using the following command: gcc prog. c common.c but now that I am using petsc, I do not know how should I include common.c in my makefile. my makefile looks like this: include ${PETSC_DIR}/lib/petsc/conf/variables include ${PETSC_DIR}/lib/petsc/conf/rules prog: prog.o chkopts -${CLINKER} -o prog.out prog.o ${PETSC_LIB} ${RM} *.o You want prog: prog.o common.o chkopts -${CLINKER} -o prog.out prog.o common.o ${PETSC_LIB} Matt .PHONY: distclean rune_1 test distclean: @rm -f *~ prog Thanks, Sepideh -- 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.caam.rice.edu/~mk51/>
