Actual source code: ex16.c

petsc-3.13.6 2020-09-29
Report Typos and Errors

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

  4:  #include <petscsys.h>
  5:  #include <petscmatlab.h>

  7: int main(int argc,char **argv)
  8: {
 10:   PetscMPIInt    rank;
 11:   char           buffer[256],*output,user[256];
 12:   PetscBool      userhappy = PETSC_FALSE;

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

 17:   PetscMatlabEngineGetOutput(PETSC_MATLAB_ENGINE_(PETSC_COMM_WORLD),&output);

 19:   PetscMatlabEngineEvaluate(PETSC_MATLAB_ENGINE_(PETSC_COMM_WORLD),"MPI_Comm_rank");
 20:   PetscSynchronizedPrintf(PETSC_COMM_WORLD,"[%d]Processor rank is %s",rank,output);
 21:   PetscSynchronizedFlush(PETSC_COMM_WORLD,PETSC_STDOUT);
 22:   PetscPrintf(PETSC_COMM_WORLD,">>");
 23:   PetscSynchronizedFGets(PETSC_COMM_WORLD,stdin,256,user);
 24:   PetscStrncmp(user,"exit",4,&userhappy);
 25:   while (!userhappy) {
 26:     PetscMatlabEngineEvaluate(PETSC_MATLAB_ENGINE_(PETSC_COMM_WORLD),user);
 27:     PetscSynchronizedPrintf(PETSC_COMM_WORLD,"[%d]The result is %s",rank,output);
 28:     PetscSynchronizedFlush(PETSC_COMM_WORLD,PETSC_STDOUT);
 29:     PetscPrintf(PETSC_COMM_WORLD,">>");
 30:     PetscSynchronizedFGets(PETSC_COMM_WORLD,stdin,256,user);
 31:     PetscStrncmp(user,"exit",4,&userhappy);
 32:   }
 33:   PetscFinalize();
 34:   return ierr;
 35: }