<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 "sread".<br><br>and nothing happen... I also tried to use sreader but matlab didn'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"><<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>></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 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 "receive", is it possible to make the inverse? Send the variable from matlab to PETSc using socket communication? can PetscMatlabEngineGet do that ? How it works?<br>
</div></blockquote>
<br>
You don't really want to use the Matlab Engine code, because with this approach the PETSc program is "in charge" and just sends work requests<br>
to Matlab. Instead you want Matlab in charge and to send work requests to PETSc.<br>
<br>
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>
PetscViewerSocketOpen(..... &socket);<br>
<br>
do forever:<br>
VecLoad(socket, &b)<br>
MatLoad(socket,....,&A)<br>
<br>
KSPSetOperators(ksp,A,A,....)<br>
KSPSolve(ksp,b,x)<br>
VecView(socket,x)<br>
<br>
You Matlab program could look something like<br>
<br>
socket = sread()<br>
<br>
do forever:<br>
<br>
Create your vector and matrix<br>
PetscBinaryWrite(socket,b)<br>
PetscBinaryWrite(socket,A)<br>
x = PetscBinaryRead(socket)<br>
<br>
The details and correct syntax are obviously not given.<br>
<br>
Good luck,<br><font color="#888888">
<br>
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 <<a href="mailto:aja2111@columbia.edu" target="_blank">aja2111@columbia.edu</a>> 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. 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 <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>> wrote:<br>
On Mon, Jul 21, 2008 at 10:14 PM, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>> wrote:<br>
><br>
> On Jul 21, 2008, at 7:57 PM, Michel Cancelliere wrote:<br>
><br>
>> Hi, I am a new user of PETSc. I am working in Reservoir Simulation and I<br>
>> have been developing the simulator inside Matlab. I have some question in<br>
>> order to understand better my possibilities of success in what I want to do:<br>
>><br>
>> • I want to solve the linear system obtained from the inner<br>
>> iterations in the newton method using PETSc, is it possible to communicate<br>
>> in an efficient way PETSc with Matlab to do that? I now that I can write<br>
>> binary files and then read with PETSc but due the size of the matrix it is a<br>
>> very time-expensive way. Where i can find some examples? I look at the<br>
>> examples within the package but I could not find it. \<br>
>> • It is possible to call PETSc library inside Matlab? Using the Mex<br>
>> files and Matlab compiler?<br>
><br>
> There is no code to do this. It is possible but pretty complicated to<br>
> write the appropriate Mex code. (Because<br>
> each Mex function is a separate shared library you cannot just write a Mex<br>
> function for each PETSc function since they<br>
> would not share the PETSc global variables. You would have to write one Mex<br>
> function that is a "gatekeeper" and calls<br>
> the requested PETSc function underneath. I've monkeyed with this a few times<br>
> but did not have the time/energy/intellect<br>
> to write code to automate this process. Give me 300,000 dollars and we could<br>
> hire someone to write this :-)<br>
><br>
> You might look at the "newly improved" socket interface in petsc-dev<br>
> (<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>
> With this you write a stand alone C PETSc program that waits at a socket,<br>
> receive the matrix and right hand side and then<br>
> sends back the solution. The code for marshalling the matrices and vector is<br>
> common between the sockets and binary files.<br>
> On the Matlab side you create a "file" that is actually a socket connection.<br>
> See src/sys/viewer/impls/socket/matlab This may<br>
> take a little poking around and you asking us a couple of questions to get<br>
> it.<br>
> Note there is no inherent support for parallelism on the PETSc side with<br>
> 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>
Matt<br>
<br>
> Barry<br>
><br>
><br>
>> Thank you very much for your time,<br>
>><br>
>> Michel Cancelliere<br>
><br>
><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>