Commits

BarryFSmith  committed 74ba865

added PetscPOpenSetMachine() and command line form

  • Participants
  • Parent commits 7a2b0e1

Comments (0)

Files changed (4)

File include/petscsys.h

 #if defined(PETSC_HAVE_POPEN)
 PETSC_EXTERN PetscErrorCode PetscPOpen(MPI_Comm,const char[],const char[],const char[],FILE **);
 PETSC_EXTERN PetscErrorCode PetscPClose(MPI_Comm,FILE*,int*);
+PETSC_EXTERN PetscErrorCode PetscPOpenSetMachine(const char[]);
 #endif
 
 PETSC_EXTERN PetscErrorCode PetscSynchronizedPrintf(MPI_Comm,const char[],...);

File src/sys/fileio/mpiuopen.c

 }
 
 #if defined(PETSC_HAVE_POPEN)
+static char PetscPOpenMachine[128] = "";
 
 #undef __FUNCT__
 #define __FUNCT__ "PetscPClose"
        Use PetscPClose() to close the file pointer when you are finished with it
        Does not work under Windows
 
+       If machine is not provided will use the value set with PetsPOpenSetMachine() if that was provided, otherwise
+       will use the machine running node zero of the communicator
+
        The program string may contain ${DISPLAY}, ${HOMEDIRECTORY} or ${WORKINGDIRECTORY}; these
     will be replaced with relevent values.
 
-.seealso: PetscFOpen(), PetscFClose(), PetscPClose()
+.seealso: PetscFOpen(), PetscFClose(), PetscPClose(), PetscPOpenSetMachine()
 
 @*/
 PetscErrorCode  PetscPOpen(MPI_Comm comm,const char machine[],const char program[],const char mode[],FILE **fp)
 
   PetscFunctionBegin;
   /* all processors have to do the string manipulation because PetscStrreplace() is a collective operation */
-  if (machine && machine[0]) {
+  if (PetscPOpenMachine[0] || (machine && machine[0])) {
     ierr = PetscStrcpy(command,"ssh ");CHKERRQ(ierr);
-    ierr = PetscStrcat(command,machine);CHKERRQ(ierr);
+    if (PetscPOpenMachine[0]) {
+      ierr = PetscStrcat(command,PetscPOpenMachine);CHKERRQ(ierr);
+    } else {
+      ierr = PetscStrcat(command,machine);CHKERRQ(ierr);
+    }
     ierr = PetscStrcat(command," \" export DISPLAY=${DISPLAY}; ");CHKERRQ(ierr);
     /*
         Copy program into command but protect the " with a \ in front of it
   PetscFunctionReturn(0);
 }
 
+#undef __FUNCT__
+#define __FUNCT__ "PetscPOpenSetMachine"
+/*@C
+      PetscPOpenSetMachine - Sets the name of the default machine to run PetscPOpen() calls on
+
+     Logically Collective on MPI_Comm, but only process 0 runs the command
+
+   Input Parameter:
+.   machine - machine to run command on or NULL to remove previous entry
+
+   Options Database:
+.   -popen_machine <machine>
+
+   Level: intermediate
+
+.seealso: PetscFOpen(), PetscFClose(), PetscPClose(), PetscPOpen()
+
+@*/
+PetscErrorCode  PetscPOpenSetMachine(const char machine[])
+{
+  PetscErrorCode ierr;
+
+  PetscFunctionBegin;
+  if (machine) {
+    ierr = PetscStrcpy(PetscPOpenMachine,machine);CHKERRQ(ierr);
+  } else {
+    PetscPOpenMachine[0] = 0;
+  }
+  PetscFunctionReturn(0);
+}
+
 #endif

File src/sys/objects/init.c

     ierr = (*PetscHelpPrintf)(comm,"-----------------------------------------------\n");CHKERRQ(ierr);
   }
 
-#if defined(PETSC_HAVE_SERVER)
+#if defined(PETSC_HAVE_POPEN)
+  {
+  char machine[128];
+  ierr = PetscOptionsGetString(NULL,"-popen_machine",machine,128,&flg1);CHKERRQ(ierr);
+  if (flg1) {
+    ierr = PetscPOpenSetMachine(machine);CHKERRQ(ierr);
+  }
+  }
+#endif
+
+#if defined(PETSC_USE_SERVER)
   flg1 = PETSC_FALSE;
   ierr = PetscOptionsGetBool(NULL,"-server",&flg1,NULL);CHKERRQ(ierr);
   if (flg1) {

File src/sys/objects/pinit.c

   }
   ierr = PetscOptionsCheckInitial_Private();CHKERRQ(ierr);
 
+
   /* SHOULD PUT IN GUARDS: Make sure logging is initialized, even if we do not print it out */
 #if defined(PETSC_USE_LOG)
   ierr = PetscLogBegin_Private();CHKERRQ(ierr);
   }
 #endif
 
-#if defined(PETSC_HAVE_SERVER)
+#if defined(PETSC_USE_SERVER)
   flg1 = PETSC_FALSE;
   ierr = PetscOptionsGetBool(NULL,"-server",&flg1,NULL);CHKERRQ(ierr);
   if (flg1) {