<div dir="ltr">Hi,<br><br>I am trying to use the function sread() but when I run the matlab program it give me this error:<br><br>-One or more output arguments not assigned during call to &quot;sread&quot;.<br><br>and nothing happen... I also tried to use sreader but matlab didn&#39;t respond, am I doing something wrong? I am using Matlab R2008a, which matlab version is the most compatible with Petsc?<br>
<br>Thank you,<br><br>Michel<br><br><div class="gmail_quote">On Mon, Jul 28, 2008 at 8:45 PM, Barry Smith <span dir="ltr">&lt;<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d"><br>
On Jul 28, 2008, at 12:33 PM, Michel Cancelliere wrote:<br>
<br>
</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<div class="Ih2E3d"><br>
Thank you for your response, I think the socket communication between Matlab and PETSc &nbsp;is what I need, I took a look to the example ex12.c and ex12.m (Simple example to show how to PETSc programs can be run from Matlab) but in this case PETSc send the Vector solution that matlab &quot;receive&quot;, is it possible to make the inverse? Send &nbsp;the variable from matlab to PETSc using socket communication? can PetscMatlabEngineGet do that ? How it works?<br>

</div></blockquote>
<br>
 &nbsp;You don&#39;t really want to use the Matlab Engine code, because with this approach the PETSc program is &quot;in charge&quot; and just sends work requests<br>
to Matlab. Instead you want Matlab in charge and to send work requests to PETSc.<br>
<br>
 &nbsp; The basic idea is that both Matlab and PETSc open a socket connection to each other. On the PETSc side use PetscViewerSocketOpen() on the Matlab side<br>
use the bin/matlab/@sreader/sreader.m class to create a (Matlab) socket object. Now on the PETSc side you can make calls to VecView() to send vectors to<br>
Matlab and VecLoad() and MatLoad() to read vectors and matrices from Matlab. On the Matlab side use PetscBinaryRead() and PetscBinaryWrite() to<br>
read vectors from PETSc and to write vectors and matrices to PETSc. Your PETSc program may end up looking something like<br>
<br>
 &nbsp; &nbsp;PetscViewerSocketOpen(..... &amp;socket);<br>
<br>
 &nbsp; do forever:<br>
 &nbsp; &nbsp; &nbsp;VecLoad(socket, &amp;b)<br>
 &nbsp; &nbsp; &nbsp;MatLoad(socket,....,&amp;A)<br>
<br>
 &nbsp; &nbsp; &nbsp;KSPSetOperators(ksp,A,A,....)<br>
 &nbsp; &nbsp; &nbsp;KSPSolve(ksp,b,x)<br>
 &nbsp; &nbsp; &nbsp;VecView(socket,x)<br>
<br>
 &nbsp; You Matlab program could look something like<br>
<br>
 &nbsp; &nbsp; &nbsp;socket = sread()<br>
<br>
 &nbsp; &nbsp; &nbsp;do forever:<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; Create your vector and matrix<br>
 &nbsp; &nbsp; &nbsp; &nbsp; PetscBinaryWrite(socket,b)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; PetscBinaryWrite(socket,A)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; x = PetscBinaryRead(socket)<br>
<br>
 &nbsp;The details and correct syntax are obviously not given.<br>
<br>
 &nbsp; Good luck,<br><font color="#888888">
<br>
 &nbsp; Barry</font><div><div></div><div class="Wj3C7c"><br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<br>
Aron, I was studying your recommendation but it means that I have to write all the function from my Matlab Code to C?, because it should take me a lot of time and this work is part of my MSc Thesis and maybe I need a less time consuming solution.<br>

<br>
Thank you in advance,<br>
<br>
Michel<br>
<br>
On Tue, Jul 22, 2008 at 8:56 PM, Aron Ahmadia &lt;<a href="mailto:aja2111@columbia.edu" target="_blank">aja2111@columbia.edu</a>&gt; wrote:<br>
Michel,<br>
<br>
I would recommend investing the time to write your C/C++ wrapper code a little higher up around the Newton iteration, since PETSc provides a great abstraction interface for it. &nbsp;Then you could write code to build the matrix (or assemble a matrix-free routine!) in C/C++, and pass the parameters in from there.<br>

<br>
~Aron<br>
<br>
<br>
On Tue, Jul 22, 2008 at 12:12 AM, Matthew Knepley &lt;<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>&gt; wrote:<br>
On Mon, Jul 21, 2008 at 10:14 PM, Barry Smith &lt;<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>&gt; wrote:<br>
&gt;<br>
&gt; On Jul 21, 2008, at 7:57 PM, Michel Cancelliere wrote:<br>
&gt;<br>
&gt;&gt; Hi, I am a new user of PETSc. I am working in Reservoir Simulation and I<br>
&gt;&gt; have been developing the simulator inside Matlab. I have some question in<br>
&gt;&gt; order to understand better my possibilities of success in what I want to do:<br>
&gt;&gt;<br>
&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp;• I want to solve the linear system obtained from the inner<br>
&gt;&gt; iterations in the newton method using PETSc, is it possible to communicate<br>
&gt;&gt; in an efficient way PETSc &nbsp;with Matlab to do that? I now that I can write<br>
&gt;&gt; binary files and then read with PETSc but due the size of the matrix it is a<br>
&gt;&gt; very time-expensive way. Where i can find some examples? I look at the<br>
&gt;&gt; examples within the package but I could not find it. \<br>
&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp;• It is possible to call PETSc library inside Matlab? Using the Mex<br>
&gt;&gt; files and Matlab compiler?<br>
&gt;<br>
&gt; &nbsp; There is no code to do this. It is possible but pretty complicated to<br>
&gt; write the appropriate Mex code. (Because<br>
&gt; each Mex function is a separate shared library you cannot just write a Mex<br>
&gt; function for each PETSc function since they<br>
&gt; would not share the PETSc global variables. You would have to write one Mex<br>
&gt; function that is a &quot;gatekeeper&quot; and calls<br>
&gt; the requested PETSc function underneath. I&#39;ve monkeyed with this a few times<br>
&gt; but did not have the time/energy/intellect<br>
&gt; to write code to automate this process. Give me 300,000 dollars and we could<br>
&gt; hire someone to write this :-)<br>
&gt;<br>
&gt; &nbsp;You might look at the &quot;newly improved&quot; socket interface in petsc-dev<br>
&gt; (<a href="http://www-unix.mcs.anl.gov/petsc/petsc-as/developers/index.html" target="_blank">http://www-unix.mcs.anl.gov/petsc/petsc-as/developers/index.html</a>).<br>
&gt; With this you write a stand alone C PETSc program that waits at a socket,<br>
&gt; receive the matrix and right hand side and then<br>
&gt; sends back the solution. The code for marshalling the matrices and vector is<br>
&gt; common between the sockets and binary files.<br>
&gt; On the Matlab side you create a &quot;file&quot; that is actually a socket connection.<br>
&gt; See src/sys/viewer/impls/socket/matlab This may<br>
&gt; take a little poking around and you asking us a couple of questions to get<br>
&gt; it.<br>
&gt; Note there is no inherent support for parallelism on the PETSc side with<br>
&gt; this setup but I think it is possible.<br>
<br>
I personally think this would be much easier in Sage than in Matlab<br>
proper. In fact,<br>
with Sage you could use petsc4py directly, and directly access the<br>
data structures<br>
as numpy arrays if necessary.<br>
<br>
&nbsp;Matt<br>
<br>
&gt; &nbsp; Barry<br>
&gt;<br>
&gt;<br>
&gt;&gt; Thank you very much for your time,<br>
&gt;&gt;<br>
&gt;&gt; Michel Cancelliere<br>
&gt;<br>
&gt;<br>
<br>
<br>
<br>
--<br>
What most experimenters take for granted before they begin their<br>
experiments is infinitely more interesting than any results to which<br>
their experiments lead.<br>
-- Norbert Wiener<br>
<br>
<br>
<br>
</blockquote>
<br>
</div></div></blockquote></div><br></div>