Matlab and PETSc communication

Barry Smith bsmith at mcs.anl.gov
Mon Jul 21 22:14:43 CDT 2008


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.

    Barry


> Thank you very much for your time,
>
> Michel Cancelliere




More information about the petsc-users mailing list