Actual source code: pdisplay.c
1: /*$Id: pdisplay.c,v 1.23 2001/03/23 23:20:45 balay Exp $*/
3: #include "petsc.h"
4: #include "petscsys.h" /*I "petscsys.h" I*/
5: #include <stdarg.h>
6: #if defined(PETSC_HAVE_STDLIB_H)
7: #include <stdlib.h>
8: #endif
9: #include "petscfix.h"
11: /*@C
12: PetscOptionsGetenv - Gets an environmental variable, broadcasts to all
13: processors in communicator from first.
15: Collective on MPI_Comm
17: Input Parameters:
18: + comm - communicator to share variable
19: . name - name of environmental variable
20: - len - amount of space allocated to hold variable
22: Output Parameters:
23: + flag - if not PETSC_NULL tells if variable found or not
24: - env - value of variable
26: Level: advanced
28: Notes:
29: You can also "set" the environmental variable by setting the options database value
30: -name "stringvalue" (with name in lower case). If name begins with PETSC_ this is
31: discarded before checking the database. For example, PETSC_VIEWER_SOCKET_PORT would
32: be given as -viewer_socket_port 9000
34: If comm does not contain the 0th process in the MPIRUN it is likely on
35: many systems that the environmental variable will not be set unless you
36: put it in a universal location like a .chsrc file
38: @*/
39: int PetscOptionsGetenv(MPI_Comm comm,const char *name,char env[],int len,PetscTruth *flag)
40: {
41: int rank,ierr;
42: char *str,work[256];
43: PetscTruth flg = PETSC_FALSE,spetsc;
44:
47: /* first check options database */
48: PetscStrncmp(name,"PETSC_",6,&spetsc);
49:
50: PetscStrcpy(work,"-");
51: if (spetsc) {
52: PetscStrcat(work,name+6);
53: } else {
54: PetscStrcat(work,name);
55: }
56: PetscStrtolower(work);
57: PetscOptionsGetString(PETSC_NULL,work,env,len,&flg);
58: if (flg) {
59: if (flag) *flag = PETSC_TRUE;
60: } else { /* now check environment */
61: PetscMemzero(env,len*sizeof(char));
63: MPI_Comm_rank(comm,&rank);
64: if (!rank) {
65: str = getenv(name);
66: if (str) flg = PETSC_TRUE;
67: if (str && env) {PetscStrncpy(env,str,len);}
68: }
69: MPI_Bcast(&flg,1,MPI_INT,0,comm);
70: MPI_Bcast(env,len,MPI_CHAR,0,comm);
71: if (flag) *flag = flg;
72: }
73: return(0);
74: }
76: /*
77: PetscSetDisplay - Tries to set the X windows display variable for all processors.
78: The variable PetscDisplay contains the X windows display variable.
80: */
81: static char PetscDisplay[128];
83: int PetscSetDisplay(void)
84: {
85: int size,rank,len,ierr;
86: PetscTruth flag;
87: char *str,display[128];
90: PetscOptionsGetString(PETSC_NULL,"-display",PetscDisplay,128,&flag);
91: if (flag) return(0);
93: MPI_Comm_size(PETSC_COMM_WORLD,&size);
94: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
95: if (!rank) {
96: str = getenv("DISPLAY");
97: if (!str || (str[0] == ':' && size > 1)) {
98: PetscGetHostName(display,124);
99: PetscStrcat(display,":0.0");
100: } else {
101: PetscStrncpy(display,str,128);
102: }
103: PetscStrlen(display,&len);
104: }
105: MPI_Bcast(&len,1,MPI_INT,0,PETSC_COMM_WORLD);
106: MPI_Bcast(display,len,MPI_CHAR,0,PETSC_COMM_WORLD);
107: display[len] = 0;
108: PetscStrcpy(PetscDisplay,display);
109: return(0);
110: }
112: /*
113: PetscGetDisplay - Gets the display variable for all processors.
115: Input Parameters:
116: . n - length of string display
118: Output Parameters:
119: . display - the display string
121: */
122: int PetscGetDisplay(char display[],int n)
123: {
127: PetscStrncpy(display,PetscDisplay,n);
128: return(0);
129: }