<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0">thanks. It works</p>
<p style="margin-top:0;margin-bottom:0">Sepideh<br>
</p>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Matthew Knepley <knepley@gmail.com><br>
<b>Sent:</b> Tuesday, April 3, 2018 5:53:56 AM<br>
<b>To:</b> Sepideh Kavousi<br>
<b>Cc:</b> petsc-users@mcs.anl.gov<br>
<b>Subject:</b> Re: [petsc-users] read variables from a source file in petsc</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div class="x_gmail_extra">
<div class="x_gmail_quote">On Mon, Apr 2, 2018 at 10:52 PM, Sepideh Kavousi <span dir="ltr">
<<a href="mailto:skavou1@lsu.edu" target="_blank">skavou1@lsu.edu</a>></span> wrote:<br>
<blockquote class="x_gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div dir="ltr">
<div id="x_m_-290898563111525184divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif">
<p style="margin-top:0; margin-bottom:0">Hi all,</p>
<p style="margin-top:0; margin-bottom:0">I wrote a petsc code, and I defined my variables in a separate file, namely common.h, and common.c as following</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">common.h:</p>
<p style="margin-top:0; margin-bottom:0"></p>
<div>
<blockquote>extern int i;<br>
extern int n;</blockquote>
</div>
</div>
</div>
</blockquote>
<div>Notice that these declarations are inconsistent for the main file.</div>
<div> </div>
<blockquote class="x_gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div dir="ltr">
<div id="x_m_-290898563111525184divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif">
<p style="margin-top:0; margin-bottom:0">common.c:<br>
</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0"></p>
<div>
<blockquote>#include <petsc.h><br>
#include "common.h<br>
PetscScalar i; // Define i and initialize<br>
PetscScalar n; // Define n and initialize<br>
i=2.2;<br>
n=3.5;</blockquote>
</div>
Now in my prog.c code I have:
<p></p>
<p style="margin-top:0; margin-bottom:0"></p>
<div>
<blockquote>#include <petsc.h><br>
#include <common.h><br>
static char help[]="program main";<br>
int main (int argc, char **argv){<br>
PetscInitialize(&argc,&argv, (char*) 0,help);<br>
PetscPrintf(PETSC_COMM_WORLD,"<wbr>i=%f!\n",a);<br>
PetscPrintf(PETSC_COMM_WORLD,"<wbr>n=%f!\n",b) ;<br>
PetscFinalize();<br>
}<br>
<br>
</blockquote>
if my it was not using petsc and it was a normal c code, I could run it using the following command:</div>
<div> gcc prog. c common.c</div>
<div>but now that I am using petsc, I do not know how should I include common.c in my makefile.</div>
<div>my makefile looks like this:</div>
<div><br>
</div>
<div>
<div>
<blockquote>include ${PETSC_DIR}/lib/petsc/conf/<wbr>variables<br>
include ${PETSC_DIR}/lib/petsc/conf/<wbr>rules<br>
prog: prog.o chkopts<br>
<blockquote>-${CLINKER} -o prog.out prog.o ${PETSC_LIB} <br>
</blockquote>
<blockquote>${RM} *.o<br>
</blockquote>
</blockquote>
</div>
<div>
<blockquote></blockquote>
</div>
</div>
</div>
</div>
</blockquote>
<div>You want</div>
<div><br>
</div>
<div>prog: prog.o common.o chkopts</div>
<div> -${CLINKER} -o prog.out prog.o common.o ${PETSC_LIB}</div>
<div><br>
</div>
<div> Matt</div>
<blockquote class="x_gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div dir="ltr">
<div id="x_m_-290898563111525184divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif">
<div>
<div>
<blockquote>.PHONY: distclean rune_1 test<br>
distclean:<br>
<blockquote>@rm -f *~ prog<br>
</blockquote>
</blockquote>
Thanks,</div>
<div>Sepideh<br>
</div>
<br>
</div>
<div><br>
</div>
<br>
<p></p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
</div>
</div>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
<div class="x_gmail_signature">
<div dir="ltr">
<div>
<div dir="ltr">
<div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener</div>
<div><br>
</div>
<div><a href="http://www.caam.rice.edu/~mk51/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>