[petsc-users] read variables from a source file in petsc
Sepideh Kavousi
skavou1 at lsu.edu
Mon Apr 2 21:52:51 CDT 2018
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;
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
.PHONY: distclean rune_1 test
distclean:
@rm -f *~ prog
Thanks,
Sepideh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20180403/0171222c/attachment.html>
More information about the petsc-users
mailing list