[petsc-users] read variables from a source file in petsc
Sepideh Kavousi
skavou1 at lsu.edu
Tue Apr 3 08:46:07 CDT 2018
thanks. It works
Sepideh
________________________________
From: Matthew Knepley <knepley at gmail.com>
Sent: Tuesday, April 3, 2018 5:53:56 AM
To: Sepideh Kavousi
Cc: petsc-users at mcs.anl.gov
Subject: Re: [petsc-users] read variables from a source file in petsc
On Mon, Apr 2, 2018 at 10:52 PM, Sepideh Kavousi <skavou1 at lsu.edu<mailto:skavou1 at lsu.edu>> 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/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20180403/4ad46a6d/attachment-0001.html>
More information about the petsc-users
mailing list