/*@C PetscEmacsClientErrorHandler - Error handler that uses the emacsclient program to load the file where the error occured. Then calls the "previous" error handler. Not Collective Input Parameters: + comm - communicator over which error occured . line - the line number of the error (indicated by __LINE__) . func - the function where error is detected (indicated by __FUNCT__) . file - the file in which the error was detected (indicated by __FILE__) . dir - the directory of the file (indicated by __SDIR__) . mess - an error text string, usually just printed to the screen . n - the generic error number . p - specific error number - ctx - error handler context Options Database Key: . -on_error_emacs <machinename> Level: developer Notes: You must put (server-start) in your .emacs file for the emacsclient software to work Most users need not directly employ this routine and the other error handlers, but can instead use the simplified interface SETERRQ, which has the calling sequence $ SETERRQ(PETSC_COMM_SELF,number,p,mess) Notes for experienced users: Use PetscPushErrorHandler() to set the desired error handler. Developer Note: Since this is an error handler it cannot call CHKERRQ(); thus we just return if an error is detected. Concepts: emacs^going to on error Concepts: error handler^going to line in emacs .seealso: PetscPushErrorHandler(), PetscAttachDebuggerErrorHandler(), PetscAbortErrorHandler() @*/ PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm comm,int line,const char *fun,const char *file,const char *dir,PetscErrorCode n,PetscErrorType p,const char *mess,void *ctx) { PetscErrorCode ierr; char command[PETSC_MAX_PATH_LEN]; const char *pdir; FILE *fp; PetscInt rval; PetscFunctionBegin; ierr = PetscGetPetscDir(&pdir);if (ierr) PetscFunctionReturn(ierr); sprintf(command,"cd %s; emacsclient --no-wait +%d %s%s\n",pdir,line,dir,file); #if defined(PETSC_HAVE_POPEN) ierr = PetscPOpen(MPI_COMM_WORLD,(char*)ctx,command,"r",&fp);if (ierr) PetscFunctionReturn(ierr); ierr = PetscPClose(MPI_COMM_WORLD,fp,&rval);if (ierr) PetscFunctionReturn(ierr); #else SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP_SYS,"Cannot run external programs on this machine"); #endif ierr = PetscPopErrorHandler();if (ierr) PetscFunctionReturn(ierr); /* remove this handler from the stack of handlers */ if (!eh) { ierr = PetscTraceBackErrorHandler(comm,line,fun,file,dir,n,p,mess,0);if (ierr) PetscFunctionReturn(ierr); } else { ierr = (*eh->handler)(comm,line,fun,file,dir,n,p,mess,eh->ctx);if (ierr) PetscFunctionReturn(ierr); } PetscFunctionReturn(ierr); }
PetscErrorCode BSSCR_GeneratePetscHeader_for_file( FILE *fd, MPI_Comm comm ) { PetscErrorCode ierr; char version[256]; char arch[50], hostname[64], username[16], pname[PETSC_MAX_PATH_LEN], date[64]; int size, rank; char *_dir; ierr = PetscGetArchType(arch, 50);CHKERRQ(ierr); ierr = PetscGetHostName(hostname, 64);CHKERRQ(ierr); ierr = PetscGetUserName(username, 16);CHKERRQ(ierr); ierr = PetscGetProgramName(pname, PETSC_MAX_PATH_LEN);CHKERRQ(ierr); ierr = PetscGetDate(date, 64);CHKERRQ(ierr); ierr = PetscGetVersion(&version,256);CHKERRQ(ierr); ierr = PetscGetPetscDir( (const char**)&_dir ); CHKERRQ(ierr); MPI_Comm_size( comm, &size ); MPI_Comm_rank( comm, &rank ); if( rank != 0 ) PetscFunctionReturn(0); if( size == 1 ) { fprintf( fd,"## %s on a %s named %s with %d processor, by %s %s\n", pname, arch, hostname, size, username, date); } else { fprintf( fd,"## %s on a %s named %s with %d processors, by %s %s\n", pname, arch, hostname, size, username, date); } fprintf( fd, "## Using %s, installed at %s \n", version, _dir ); PetscFunctionReturn(0); }
PetscErrorCode BSSCR_GeneratePetscHeader_for_viewer( PetscViewer viewer ) { PetscErrorCode ierr; char version[256]; char arch[50], hostname[64], username[16], pname[PETSC_MAX_PATH_LEN], date[64]; int size; char *_dir; MPI_Comm comm; ierr = PetscGetArchType(arch, 50);CHKERRQ(ierr); ierr = PetscGetHostName(hostname, 64);CHKERRQ(ierr); ierr = PetscGetUserName(username, 16);CHKERRQ(ierr); ierr = PetscGetProgramName(pname, PETSC_MAX_PATH_LEN);CHKERRQ(ierr); ierr = PetscGetDate(date, 64);CHKERRQ(ierr); ierr = PetscGetVersion(&version,256);CHKERRQ(ierr); ierr = PetscGetPetscDir( (const char**)&_dir ); CHKERRQ(ierr); PetscObjectGetComm( (PetscObject)viewer, &comm ); MPI_Comm_size( comm, &size ); if( size == 1 ) { PetscViewerASCIIPrintf( viewer,"## %s on a %s named %s with %d processor, by %s %s\n", pname, arch, hostname, size, username, date); } else { PetscViewerASCIIPrintf( viewer,"## %s on a %s named %s with %d processors, by %s %s\n", pname, arch, hostname, size, username, date); } PetscViewerASCIIPrintf( viewer, "## Using %s, installed at %s \n", version, _dir ); PetscFunctionReturn(0); }
/*@C PetscFileRetrieve - Obtains a library from a URL or compressed and copies into local disk space as uncompressed. Collective on MPI_Comm Input Parameter: + comm - processors accessing the library . libname - name of library, including entire URL (with or without .gz) - llen - length of llibname Output Parameter: + llibname - name of local copy of library - found - if found and retrieved the file Level: developer @*/ PetscErrorCode PetscFileRetrieve(MPI_Comm comm,const char libname[],char llibname[],size_t llen,PetscBool *found) { char buf[1024],tmpdir[PETSC_MAX_PATH_LEN],urlget[PETSC_MAX_PATH_LEN],*par; const char *pdir; FILE *fp; PetscErrorCode ierr; int i; PetscMPIInt rank; size_t len = 0; PetscBool flg1,flg2,flg3,sharedtmp,exists; #if defined(PETSC_HAVE_POPEN) int rval; #endif PetscFunctionBegin; *found = PETSC_FALSE; /* if file does not have an ftp:// or http:// or .gz then need not process file */ ierr = PetscStrstr(libname,".gz",&par);CHKERRQ(ierr); if (par) {ierr = PetscStrlen(par,&len);CHKERRQ(ierr);} ierr = PetscStrncmp(libname,"ftp://",6,&flg1);CHKERRQ(ierr); ierr = PetscStrncmp(libname,"http://",7,&flg2);CHKERRQ(ierr); ierr = PetscStrncmp(libname,"file://",7,&flg3);CHKERRQ(ierr); if (!flg1 && !flg2 && !flg3 && (!par || len != 3)) { ierr = PetscStrncpy(llibname,libname,llen);CHKERRQ(ierr); ierr = PetscTestFile(libname,'r',found);CHKERRQ(ierr); if (*found) { ierr = PetscInfo1(NULL,"Found file %s\n",libname);CHKERRQ(ierr); } else { ierr = PetscInfo1(NULL,"Did not find file %s\n",libname);CHKERRQ(ierr); } PetscFunctionReturn(0); } if (par && len == 3){ size_t llen; ierr = PetscStrlen(libname,&llen);CHKERRQ(ierr); ierr = PetscStrncpy(llibname,libname,llen);CHKERRQ(ierr); llibname[llen-len] = 0; ierr = PetscTestFile(llibname,'r',found);CHKERRQ(ierr); if (*found) { ierr = PetscInfo1(NULL,"Found uncompressed version of file %s\n",llibname);CHKERRQ(ierr); PetscFunctionReturn(0); } else { ierr = PetscInfo1(NULL,"Did not find uncompressed version of file %s\n",libname);CHKERRQ(ierr); } } /* Determine if all processors share a common /tmp */ ierr = PetscSharedTmp(comm,&sharedtmp);CHKERRQ(ierr); ierr = PetscOptionsGetenv(comm,"PETSC_TMP",tmpdir,PETSC_MAX_PATH_LEN,&flg1);CHKERRQ(ierr); ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); if (!rank || !sharedtmp) { /* Construct the script to get URL file */ ierr = PetscGetPetscDir(&pdir);CHKERRQ(ierr); ierr = PetscStrcpy(urlget,pdir);CHKERRQ(ierr); ierr = PetscStrcat(urlget,"/bin/urlget");CHKERRQ(ierr); ierr = PetscTestFile(urlget,'r',&exists);CHKERRQ(ierr); if (!exists) { ierr = PetscTestFile("urlget",'r',&exists);CHKERRQ(ierr); if (!exists) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Cannot locate PETSc script urlget in %s or current directory",urlget); ierr = PetscStrcpy(urlget,"urlget");CHKERRQ(ierr); } ierr = PetscStrcat(urlget," ");CHKERRQ(ierr); /* are we using an alternative /tmp? */ if (flg1) { ierr = PetscStrcat(urlget,"-tmp ");CHKERRQ(ierr); ierr = PetscStrcat(urlget,tmpdir);CHKERRQ(ierr); ierr = PetscStrcat(urlget," ");CHKERRQ(ierr); } ierr = PetscStrcat(urlget,libname);CHKERRQ(ierr); ierr = PetscStrcat(urlget," 2>&1 ");CHKERRQ(ierr); #if defined(PETSC_HAVE_POPEN) ierr = PetscPOpen(PETSC_COMM_SELF,NULL,urlget,"r",&fp);CHKERRQ(ierr); #else SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP_SYS,"Cannot run external programs on this machine"); #endif if (!fgets(buf,1024,fp)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_PLIB,"No output from ${PETSC_DIR}/bin/urlget in getting file %s",libname); ierr = PetscInfo1(0,"Message back from urlget: %s\n",buf);CHKERRQ(ierr); ierr = PetscStrncmp(buf,"Error",5,&flg1);CHKERRQ(ierr); ierr = PetscStrncmp(buf,"Traceback",9,&flg2);CHKERRQ(ierr); #if defined(PETSC_HAVE_POPEN) ierr = PetscPClose(PETSC_COMM_SELF,fp,&rval);CHKERRQ(ierr); #endif if (flg1 || flg2) *found = PETSC_FALSE; else { *found = PETSC_TRUE; /* Check for \n and make it 0 */ for (i=0; i<1024; i++) { if (buf[i] == '\n') { buf[i] = 0; break; } } ierr = PetscStrncpy(llibname,buf,llen);CHKERRQ(ierr); } } if (sharedtmp) { /* send library name to all processors */ ierr = MPI_Bcast(found,1,MPIU_BOOL,0,comm);CHKERRQ(ierr); if (*found) { ierr = MPI_Bcast(llibname,llen,MPI_CHAR,0,comm);CHKERRQ(ierr); ierr = MPI_Bcast(found,1,MPIU_BOOL,0,comm);CHKERRQ(ierr); } } PetscFunctionReturn(0); }