1 2 static char help[] = "Demonstrates PetscMatlabEngineXXX()\n"; 3 4 #include <petscsys.h> 5 #include <petscmatlab.h> 6 7 int main(int argc,char **argv) 8 { 9 PetscMPIInt rank; 10 char buffer[256],*output,user[256]; 11 PetscBool userhappy = PETSC_FALSE; 12 13 PetscCall(PetscInitialize(&argc,&argv,(char*)0,help)); 14 PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD,&rank)); 15 16 PetscCall(PetscMatlabEngineGetOutput(PETSC_MATLAB_ENGINE_(PETSC_COMM_WORLD),&output)); 17 18 PetscCall(PetscMatlabEngineEvaluate(PETSC_MATLAB_ENGINE_(PETSC_COMM_WORLD),"MPI_Comm_rank")); 19 PetscCall(PetscSynchronizedPrintf(PETSC_COMM_WORLD,"[%d]Processor rank is %s",rank,output)); 20 PetscCall(PetscSynchronizedFlush(PETSC_COMM_WORLD,PETSC_STDOUT)); 21 PetscCall(PetscPrintf(PETSC_COMM_WORLD,">>")); 22 PetscCall(PetscSynchronizedFGets(PETSC_COMM_WORLD,stdin,256,user)); 23 PetscCall(PetscStrncmp(user,"exit",4,&userhappy)); 24 while (!userhappy) { 25 PetscCall(PetscMatlabEngineEvaluate(PETSC_MATLAB_ENGINE_(PETSC_COMM_WORLD),user)); 26 PetscCall(PetscSynchronizedPrintf(PETSC_COMM_WORLD,"[%d]The result is %s",rank,output)); 27 PetscCall(PetscSynchronizedFlush(PETSC_COMM_WORLD,PETSC_STDOUT)); 28 PetscCall(PetscPrintf(PETSC_COMM_WORLD,">>")); 29 PetscCall(PetscSynchronizedFGets(PETSC_COMM_WORLD,stdin,256,user)); 30 PetscCall(PetscStrncmp(user,"exit",4,&userhappy)); 31 } 32 PetscCall(PetscFinalize()); 33 return 0; 34 } 35