Matlab and PETSc communication

Michel Cancelliere fernandez858 at gmail.com
Mon Jul 28 12:33:54 CDT 2008


Hi,
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?

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.

Thank you in advance,

Michel

On Tue, Jul 22, 2008 at 8:56 PM, Aron Ahmadia <aja2111 at columbia.edu> wrote:

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


More information about the petsc-users mailing list