[petsc-users] coupling with Matlab and parallel solution

Barry Smith bsmith at mcs.anl.gov
Fri Sep 3 14:25:56 CDT 2010


   Ben

   Ok, I figured out the problem. It is not fundamental and mostly comes from not having a create way to debug this.

   The test vector you create is sequential then you try to view it back to Matlab with the parallel fd viewer. If you change to 
  ierr = VecCreateMPI(PETSC_COMM_WORLD,PETSC_DECIDE,1,&test);CHKERRQ(ierr);
then the code runs.

   I've found (just now) that when I use launch all the output from the .c program gets lost which makes it impossible to figure out what has gone wrong. You can debug by running the two parts of the computation in two different windows. So comment out the launch from the matlab script and then in Matlab run the script (it will hang waiting for the socket to work) and in a separate terminal window run the .c program; for example petscmpiexec -n 2 ./ex1 -info Now you see exactly what is happening in the PETSc program. You can even use -start_in_debugger on the PETSc side to run the debugger on crashes.

   I'll add this to the docs for launch

   Barry

     
On Sep 2, 2010, at 3:28 PM, Benjamin Sanderse wrote:

> Hi Barry,
> 
> I attached my matlab file, c file and makefile. First I generate the executable with 'make petsc_poisson_par_barry' and then I run test_petsc_par_barry.m. 
> If you change MATMPIAIJ to MATAIJ and VECMPI to VECSEQ the code works fine.
> 
> Thanks a lot,
> 
> Benjamin
> 
> <makefile><test_petsc_par_barry.m><petsc_poisson_par_barry.c>
> 
> Op 2 sep 2010, om 13:45 heeft Barry Smith het volgende geschreven:
> 
>> 
>> 
>> Matlab is never aware the vector is parallel. Please send me the code and I'll figure out what is going on.
>> 
>>  Barry
>> 
>> On Sep 2, 2010, at 2:07 PM, Benjamin Sanderse wrote:
>> 
>>> That sounds great, but there is one issue I am encountering. I switched vector types to VECMPI and matrix type to MATMPIAIJ, but when running Matlab I get the following error:
>>> 
>>> Found unrecogonized header 0 in file. If your file contains complex numbers
>>> then call PetscBinaryRead() with "complex" as the second argument
>>> Error in ==> PetscBinaryRead at 27
>>> if nargin < 2
>>> 
>>> ??? Output argument "varargout" (and maybe others) not assigned during call to 
>>> "/ufs/sanderse/Software/petsc-3.1-p4/bin/matlab/PetscBinaryRead.m>PetscBinaryRead".
>>> 
>>> Error in ==> test_petsc_par at 57
>>> 	x4 = PetscBinaryReady(PS);
>>> 
>>> Could it be that Matlab does not understand the "parallel" vector which is returned by Petsc? Currently I have this done with VecView as follows:
>>> 
>>> fd = PETSC_VIEWER_SOCKET_WORLD;
>>> ...
>>> KSPSolve(ksp,b,x);
>>> ...
>>> VecView(fd,x);
>>> 
>>> Thanks for the help!
>>> 
>>> Ben
>>> 
>>> Op 2 sep 2010, om 10:09 heeft Barry Smith het volgende geschreven:
>>> 
>>>> 
>>>> On Sep 2, 2010, at 10:51 AM, Benjamin Sanderse wrote:
>>>> 
>>>>> Hello all,
>>>>> 
>>>>> I figured out the coupling with Matlab and I can send back and forth matrices and vectors between Petsc and Matlab. Actually, I send only once a matrix from Matlab to Petsc and then repeatedly send new right hand sides from Matlab->Petsc and the solution vector from Petsc->Matlab. That works great.
>>>>> I know want to see if the matrix that is send from (serial) Matlab to Petsc can be stored as a parallel matrix in Petsc so that subsequent computations with different right hand sides can be performed in parallel by Petsc. Does this simply work by using MatLoad and setting Mattype MPIAIJ? Or is something more fancy required?
>>>> 
>>>> In theory this can be done using the same code as sequential only with parallel vectors VECMPI  and matrices. MATMPIAIJ
>>>> 
>>>> Barry
>>>> 
>>>>> 
>>>>> Thanks,
>>>>> 
>>>>> Ben
>>>> 
>>> 
>> 
> 



More information about the petsc-users mailing list