Actual source code: ex31.c
petsc-3.12.4 2020-02-04
Report Typos and Errors

      1: static const char help[] = "Demonstrates PetscMatlabEngineXXX()\n";

      3:  #include <petscvec.h>
      4:  #include <petscmatlab.h>

      6: int main(int argc,char **argv)
      7: {
      9:   PetscMPIInt    rank;
     10:   PetscInt       n = 5;
     11:   char           *output;
     12:   Vec            x;

     14:   PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;

     16:   VecCreate(PETSC_COMM_WORLD,&x);
     17:   VecSetSizes(x,PETSC_DECIDE,n);
     18:   VecSetFromOptions(x);

     20:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
     21:   PetscMatlabEngineGetOutput(PETSC_MATLAB_ENGINE_WORLD,&output);
     22:   PetscMatlabEngineEvaluate(PETSC_MATLAB_ENGINE_WORLD,"MPI_Comm_rank");
     23:   PetscSynchronizedPrintf(PETSC_COMM_WORLD,"[%d]Processor rank is %s",rank,output);
     24:   PetscSynchronizedFlush(PETSC_COMM_WORLD,PETSC_STDOUT);

     26:   PetscObjectSetName((PetscObject)x,"x");
     27:   PetscMatlabEnginePut(PETSC_MATLAB_ENGINE_WORLD,(PetscObject)x);
     28:   PetscMatlabEngineEvaluate(PETSC_MATLAB_ENGINE_WORLD,"x = x + MPI_Comm_rank;\n");
     29:   PetscMatlabEngineGet(PETSC_MATLAB_ENGINE_WORLD,(PetscObject)x);

     31:   PetscMatlabEngineEvaluate(PETSC_MATLAB_ENGINE_WORLD,"whos\n");
     32:   PetscSynchronizedPrintf(PETSC_COMM_WORLD,"[%d]The result is %s",rank,output);
     33:   PetscSynchronizedFlush(PETSC_COMM_WORLD,PETSC_STDOUT);

     35:   VecView(x,PETSC_VIEWER_STDOUT_WORLD);
     36:   VecDestroy(&x);
     37:   PetscFinalize();
     38:   return ierr;
     39: }