Actual source code: ex16.c
petsc-3.6.1 2015-08-06
2: static char help[] = "Demonstrates PetscMatlabEngineXXX()\n";
4: #include <petscsys.h>
5: #include <petscmatlab.h>
9: int main(int argc,char **argv)
10: {
12: PetscMPIInt rank;
13: char buffer[256],*output,user[256];
14: PetscBool userhappy = PETSC_FALSE;
16: PetscInitialize(&argc,&argv,(char*)0,help);
17: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
19: PetscMatlabEngineGetOutput(PETSC_MATLAB_ENGINE_(PETSC_COMM_WORLD),&output);
21: PetscMatlabEngineEvaluate(PETSC_MATLAB_ENGINE_(PETSC_COMM_WORLD),"MPI_Comm_rank");
22: PetscSynchronizedPrintf(PETSC_COMM_WORLD,"[%d]Processor rank is %s",rank,output);
23: PetscSynchronizedFlush(PETSC_COMM_WORLD,PETSC_STDOUT);
24: PetscPrintf(PETSC_COMM_WORLD,">>");
25: PetscSynchronizedFGets(PETSC_COMM_WORLD,stdin,256,user);
26: PetscStrncmp(user,"exit",4,&userhappy);
27: while (!userhappy) {
28: PetscMatlabEngineEvaluate(PETSC_MATLAB_ENGINE_(PETSC_COMM_WORLD),user);
29: PetscSynchronizedPrintf(PETSC_COMM_WORLD,"[%d]The result is %s",rank,output);
30: PetscSynchronizedFlush(PETSC_COMM_WORLD,PETSC_STDOUT);
31: PetscPrintf(PETSC_COMM_WORLD,">>");
32: PetscSynchronizedFGets(PETSC_COMM_WORLD,stdin,256,user);
33: PetscStrncmp(user,"exit",4,&userhappy);
34: }
35: PetscFinalize();
36: return 0;
37: }