xref: /petsc/src/sys/objects/ftn-custom/zstart.c (revision 9895aa37ac365bac650f6bd8bf977519f7222510)
1 /*
2   This file contains Fortran stubs for PetscInitialize and Finalize.
3 */
4 
5 /*
6     This is to prevent the Cray T3D version of MPI (University of Edinburgh)
7   from stupidly redefining MPI_INIT(). They put this in to detect errors
8   in C code,but here I do want to be calling the Fortran version from a
9   C subroutine.
10 */
11 #define T3DMPI_FORTRAN
12 #define T3EMPI_FORTRAN
13 
14 #define PETSC_DESIRE_COMPLEX
15 #include <petsc-private/fortranimpl.h>
16 
17 #if defined(PETSC_HAVE_CUSP)
18 #include <cublas.h>
19 #endif
20 #include <petscthreadcomm.h>
21 
22 extern PetscBool PetscBeganMPI;
23 
24 extern PetscBool PetscHMPIWorker;
25 
26 #if defined(PETSC_HAVE_FORTRAN_CAPS)
27 #define petscinitialize_              PETSCINITIALIZE
28 #define petscfinalize_                PETSCFINALIZE
29 #define petscend_                     PETSCEND
30 #define iargc_                        IARGC
31 #define getarg_                       GETARG
32 #define mpi_init_                     MPI_INIT
33 #define petscgetcommoncomm_           PETSCGETCOMMONCOMM
34 #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
35 #define petscinitialize_              petscinitialize
36 #define petscfinalize_                petscfinalize
37 #define petscend_                     petscend
38 #define mpi_init_                     mpi_init
39 #define iargc_                        iargc
40 #define getarg_                       getarg
41 #define petscgetcommoncomm_           petscgetcommoncomm
42 #endif
43 
44 #if defined(PETSC_HAVE_NAGF90)
45 #undef iargc_
46 #undef getarg_
47 #define iargc_  f90_unix_MP_iargc
48 #define getarg_ f90_unix_MP_getarg
49 #endif
50 #if defined(PETSC_USE_NARGS) /* Digital Fortran */
51 #undef iargc_
52 #undef getarg_
53 #define iargc_  NARGS
54 #define getarg_ GETARG
55 #elif defined(PETSC_HAVE_PXFGETARG_NEW)  /* cray x1 */
56 #undef iargc_
57 #undef getarg_
58 #define iargc_  ipxfargc_
59 #define getarg_ pxfgetarg_
60 #endif
61 #if defined(PETSC_HAVE_FORTRAN_IARGC_UNDERSCORE) /* HPUX + no underscore */
62 #undef iargc_
63 #undef getarg_
64 #define iargc_   iargc_
65 #define getarg_  getarg_
66 #endif
67 #if defined(PETSC_HAVE_GFORTRAN_IARGC) /* gfortran from gcc4 */
68 #undef iargc_
69 #undef getarg_
70 #define iargc_  _gfortran_iargc
71 #define getarg_ _gfortran_getarg_i4
72 #elif defined(PETSC_HAVE_BGL_IARGC) /* bgl g77 has different external & internal name mangling */
73 #undef iargc_
74 #undef getarg_
75 #define iargc  iargc_
76 #define getarg getarg_
77 #endif
78 
79 /*
80     The extra _ is because the f2c compiler puts an
81   extra _ at the end if the original routine name
82   contained any _.
83 */
84 #if defined(PETSC_HAVE_FORTRAN_UNDERSCORE_UNDERSCORE)
85 #undef mpi_init_
86 #define mpi_init_             mpi_init__
87 #endif
88 
89 EXTERN_C_BEGIN
90 extern void PETSC_STDCALL mpi_init_(int*);
91 extern void PETSC_STDCALL petscgetcommoncomm_(PetscMPIInt*);
92 
93 /*
94      Different Fortran compilers handle command lines in different ways
95 */
96 #if defined(PETSC_USE_NARGS)
97 extern short __stdcall NARGS();
98 extern void  __stdcall GETARG(short*,char*,int,short *);
99 
100 #elif defined(PETSC_HAVE_FORTRAN_STDCALL)
101 extern int  PETSC_STDCALL IARGC();
102 extern void PETSC_STDCALL GETARG(int *,char *,int);
103 
104 #elif defined(PETSC_HAVE_PXFGETARG_NEW)
105 extern int  iargc_();
106 extern void getarg_(int*,char*,int*,int*,int);
107 
108 #else
109 extern int  iargc_();
110 extern void getarg_(int*,char*,int);
111 /*
112       The Cray T3D/T3E use the PXFGETARG() function
113 */
114 #if defined(PETSC_HAVE_PXFGETARG)
115 extern void PXFGETARG(int*,_fcd,int*,int*);
116 #endif
117 #endif
118 EXTERN_C_END
119 
120 #if (defined(PETSC_HAVE_COMPLEX) && !defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX)) || defined(PETSC_USE_REAL___FLOAT128)
121 extern MPI_Op MPIU_SUM;
122 EXTERN_C_BEGIN
123 extern void MPIAPI PetscSum_Local(void*,void*,PetscMPIInt*,MPI_Datatype*);
124 EXTERN_C_END
125 #endif
126 #if defined(PETSC_USE_REAL___FLOAT128)
127 EXTERN_C_BEGIN
128 void MPIAPI PetscSum_Local(void*,void*,PetscMPIInt*,MPI_Datatype*);
129 void MPIAPI PetscMax_Local(void*,void*,PetscMPIInt*,MPI_Datatype*);
130 void MPIAPI PetscMin_Local(void*,void*,PetscMPIInt*,MPI_Datatype*);
131 EXTERN_C_END
132 #endif
133 
134 extern MPI_Op PetscMaxSum_Op;
135 
136 EXTERN_C_BEGIN
137 extern void MPIAPI PetscMaxSum_Local(void*,void*,PetscMPIInt*,MPI_Datatype*);
138 extern PetscMPIInt MPIAPI Petsc_DelCounter(MPI_Comm,PetscMPIInt,void*,void*);
139 extern PetscMPIInt MPIAPI Petsc_DelComm(MPI_Comm,PetscMPIInt,void*,void*);
140 EXTERN_C_END
141 
142 extern PetscErrorCode  PetscOptionsCheckInitial_Private(void);
143 extern PetscErrorCode  PetscOptionsCheckInitial_Components(void);
144 extern PetscErrorCode  PetscInitialize_DynamicLibraries(void);
145 #if defined(PETSC_USE_LOG)
146 extern PetscErrorCode  PetscLogBegin_Private(void);
147 #endif
148 extern PetscErrorCode  PetscMallocAlign(size_t,int,const char[],const char[],const char[],void**);
149 extern PetscErrorCode  PetscFreeAlign(void*,int,const char[],const char[],const char[]);
150 extern int  PetscGlobalArgc;
151 extern char **PetscGlobalArgs;
152 
153 /*
154     Reads in Fortran command line argments and sends them to
155   all processors and adds them to Options database.
156 */
157 
158 PetscErrorCode PETScParseFortranArgs_Private(int *argc,char ***argv)
159 {
160 #if defined(PETSC_USE_NARGS)
161   short          i,flg;
162 #else
163   int            i;
164 #endif
165   PetscErrorCode ierr;
166   int            warg = 256;
167   PetscMPIInt    rank;
168   char           *p;
169 
170   ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr);
171   if (!rank) {
172 #if defined(PETSC_HAVE_IARG_COUNT_PROGNAME)
173     *argc = iargc_();
174 #else
175     /* most compilers do not count the program name for argv[0] */
176     *argc = 1 + iargc_();
177 #endif
178   }
179   ierr = MPI_Bcast(argc,1,MPI_INT,0,PETSC_COMM_WORLD);CHKERRQ(ierr);
180 
181   /* PetscTrMalloc() not yet set, so don't use PetscMalloc() */
182   ierr = PetscMallocAlign((*argc+1)*(warg*sizeof(char)+sizeof(char*)),0,0,0,0,(void**)argv);CHKERRQ(ierr);
183   (*argv)[0] = (char*)(*argv + *argc + 1);
184 
185   if (!rank) {
186     ierr = PetscMemzero((*argv)[0],(*argc)*warg*sizeof(char));CHKERRQ(ierr);
187     for (i=0; i<*argc; i++) {
188       (*argv)[i+1] = (*argv)[i] + warg;
189 #if defined(PETSC_HAVE_PXFGETARG_NEW)
190       {char *tmp = (*argv)[i];
191       int ilen;
192       getarg_(&i,tmp,&ilen,&ierr,warg);CHKERRQ(ierr);
193       tmp[ilen] = 0;}
194 #elif defined(PETSC_USE_NARGS)
195       GETARG(&i,(*argv)[i],warg,&flg);
196 #else
197       /*
198       Because the stupid #defines above define all kinds of things to getarg_ we cannot do this test
199       #elif defined(PETSC_HAVE_GETARG)
200       getarg_(&i,(*argv)[i],warg);
201       #else
202          SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot get Fortran command line arguments");
203       */
204       getarg_(&i,(*argv)[i],warg);
205 #endif
206       /* zero out garbage at end of each argument */
207       p = (*argv)[i] + warg-1;
208       while (p > (*argv)[i]) {
209         if (*p == ' ') *p = 0;
210         p--;
211       }
212     }
213   }
214   ierr = MPI_Bcast((*argv)[0],*argc*warg,MPI_CHAR,0,PETSC_COMM_WORLD);CHKERRQ(ierr);
215   if (rank) {
216     for (i=0; i<*argc; i++) (*argv)[i+1] = (*argv)[i] + warg;
217   }
218   return 0;
219 }
220 
221 /* -----------------------------------------------------------------------------------------------*/
222 
223 extern MPI_Op PetscADMax_Op;
224 extern MPI_Op PetscADMin_Op;
225 EXTERN_C_BEGIN
226 extern void MPIAPI PetscADMax_Local(void*,void*,PetscMPIInt*,MPI_Datatype*);
227 extern void MPIAPI PetscADMin_Local(void*,void*,PetscMPIInt*,MPI_Datatype*);
228 EXTERN_C_END
229 
230 
231 EXTERN_C_BEGIN
232 /*
233     petscinitialize - Version called from Fortran.
234 
235     Notes:
236       Since this is called from Fortran it does not return error codes
237 
238 */
239 void PETSC_STDCALL petscinitialize_(CHAR filename PETSC_MIXED_LEN(len),PetscErrorCode *ierr PETSC_END_LEN(len))
240 {
241 #if defined (PETSC_USE_NARGS)
242   short       flg,i;
243 #else
244   int         i;
245 #if !defined(PETSC_HAVE_PXFGETARG_NEW) && !defined (PETSC_HAVE_PXFGETARG_NEW)
246   int         j;
247 #endif
248 #endif
249   int         flag;
250   PetscMPIInt size;
251   char        *t1,name[256],hostname[64];
252   PetscMPIInt f_petsc_comm_world;
253   PetscInt    nodesize;
254   PetscBool   flg;
255 
256   *ierr = PetscMemzero(name,256); if (*ierr) return;
257   if (PetscInitializeCalled) {*ierr = 0; return;}
258 
259   /* this must be initialized in a routine, not as a constant declaration*/
260   PETSC_STDOUT = stdout;
261   PETSC_STDERR = stderr;
262 
263   *ierr = PetscOptionsCreate();
264   if (*ierr) return;
265   i = 0;
266 #if defined (PETSC_HAVE_PXFGETARG_NEW)
267   { int ilen,sierr;
268     getarg_(&i,name,&ilen,&sierr,256);
269     if (sierr) PetscStrncpy(name,"Unknown Name",256);
270     else name[ilen] = 0;
271   }
272 #elif defined(PETSC_USE_NARGS)
273   GETARG(&i,name,256,&flg);
274 #else
275   getarg_(&i,name,256);
276   /* Eliminate spaces at the end of the string */
277   for (j=254; j>=0; j--) {
278     if (name[j] != ' ') {
279       name[j+1] = 0;
280       break;
281     }
282   }
283   if (j<0) PetscStrncpy(name,"Unknown Name",256);
284 #endif
285   *ierr = PetscSetProgramName(name);
286   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize: Calling PetscSetProgramName()\n");return;}
287 
288   /* check if PETSC_COMM_WORLD is initialized by the user in fortran */
289   petscgetcommoncomm_(&f_petsc_comm_world);
290   MPI_Initialized(&flag);
291   if (!flag) {
292     PetscMPIInt mierr;
293 
294     if (f_petsc_comm_world) {(*PetscErrorPrintf)("You cannot set PETSC_COMM_WORLD if you have not initialized MPI first\n");return;}
295     /* MPI requires calling Fortran mpi_init() if main program is Fortran */
296     mpi_init_(&mierr);
297     if (mierr) {
298       *ierr = mierr;
299       (*PetscErrorPrintf)("PetscInitialize: Calling Fortran MPI_Init()\n");
300       return;
301     }
302     PetscBeganMPI = PETSC_TRUE;
303   }
304   if (f_petsc_comm_world) PETSC_COMM_WORLD = MPI_Comm_f2c(*(MPI_Fint*)&f_petsc_comm_world); /* User called MPI_INITIALIZE() and changed PETSC_COMM_WORLD */
305   else PETSC_COMM_WORLD = MPI_COMM_WORLD;
306   PetscInitializeCalled = PETSC_TRUE;
307 
308   *ierr = PetscErrorPrintfInitialize();
309   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize: Calling PetscErrorPrintfInitialize()\n");return;}
310   *ierr = MPI_Comm_rank(MPI_COMM_WORLD,&PetscGlobalRank);
311   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize: Setting PetscGlobalRank\n");return;}
312   *ierr = MPI_Comm_size(MPI_COMM_WORLD,&PetscGlobalSize);
313   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize: Setting PetscGlobalSize\n");return;}
314 
315   MPIU_BOOL = MPI_INT;
316   MPIU_ENUM = MPI_INT;
317 
318 #if defined(PETSC_HAVE_COMPLEX)
319   /*
320      Initialized the global variable; this is because with
321      shared libraries the constructors for global variables
322      are not called; at least on IRIX.
323   */
324   {
325 #if defined(PETSC_CLANGUAGE_CXX)
326     PetscComplex ic(0.0,1.0);
327     PETSC_i = ic;
328 #else
329     PETSC_i = _Complex_I;
330 #endif
331   }
332 
333 #if !defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX)
334   *ierr = MPI_Type_contiguous(2,MPI_DOUBLE,&MPIU_C_DOUBLE_COMPLEX);
335   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI types\n");return;}
336   *ierr = MPI_Type_commit(&MPIU_C_DOUBLE_COMPLEX);
337   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI types\n");return;}
338   *ierr = MPI_Type_contiguous(2,MPI_FLOAT,&MPIU_C_COMPLEX);
339   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI types\n");return;}
340   *ierr = MPI_Type_commit(&MPIU_C_COMPLEX);
341   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI types\n");return;}
342   *ierr = MPI_Op_create(PetscSum_Local,1,&MPIU_SUM);
343   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI ops\n");return;}
344 #endif
345 
346 #endif
347 
348 #if defined(PETSC_USE_REAL___FLOAT128)
349   *ierr = MPI_Type_contiguous(2,MPI_DOUBLE,&MPIU___FLOAT128);
350   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI types\n");return;}
351   *ierr = MPI_Type_commit(&MPIU___FLOAT128);
352   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI types\n");return;}
353 #if defined(PETSC_HAVE_COMPLEX)
354   *ierr = MPI_Type_contiguous(4,MPI_DOUBLE,&MPIU___COMPLEX128);
355   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI types\n");return;}
356   *ierr = MPI_Type_commit(&MPIU___COMPLEX128);
357   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI types\n");return;}
358 #endif
359   *ierr = MPI_Op_create(PetscSum_Local,1,&MPIU_SUM);
360   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI ops\n");return;}
361   *ierr = MPI_Op_create(PetscMax_Local,1,&MPIU_MAX);
362   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI ops\n");return;}
363   *ierr = MPI_Op_create(PetscMin_Local,1,&MPIU_MIN);
364   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI ops\n");return;}
365 #endif
366 
367   /*
368        Create the PETSc MPI reduction operator that sums of the first
369      half of the entries and maxes the second half.
370   */
371   *ierr = MPI_Op_create(PetscMaxSum_Local,1,&PetscMaxSum_Op);
372   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI ops\n");return;}
373 
374   *ierr = MPI_Type_contiguous(2,MPIU_SCALAR,&MPIU_2SCALAR);
375   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI types\n");return;}
376   *ierr = MPI_Type_commit(&MPIU_2SCALAR);
377   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI types\n");return;}
378 #if defined(PETSC_USE_64BIT_INDICES) || !defined(MPI_2INT)
379   *ierr = MPI_Type_contiguous(2,MPIU_INT,&MPIU_2INT);
380   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI types\n");return;}
381   *ierr = MPI_Type_commit(&MPIU_2INT);
382   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI types\n");return;}
383 #endif
384   *ierr = MPI_Op_create(PetscADMax_Local,1,&PetscADMax_Op);
385   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI ops\n");return;}
386   *ierr = MPI_Op_create(PetscADMin_Local,1,&PetscADMin_Op);
387   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI ops\n");return;}
388   *ierr = MPI_Keyval_create(MPI_NULL_COPY_FN,Petsc_DelCounter,&Petsc_Counter_keyval,(void*)0);
389   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI keyvals\n");return;}
390   *ierr = MPI_Keyval_create(MPI_NULL_COPY_FN,Petsc_DelComm,&Petsc_InnerComm_keyval,(void*)0);
391   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI keyvals\n");return;}
392   *ierr = MPI_Keyval_create(MPI_NULL_COPY_FN,Petsc_DelComm,&Petsc_OuterComm_keyval,(void*)0);
393   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI keyvals\n");return;}
394 
395   /*
396      PetscInitializeFortran() is called twice. Here it initializes
397      PETSC_NULL_CHARACTER_Fortran. Below it initializes the PETSC_VIEWERs.
398      The PETSC_VIEWERs have not been created yet, so they must be initialized
399      below.
400   */
401   PetscInitializeFortran();
402   PETScParseFortranArgs_Private(&PetscGlobalArgc,&PetscGlobalArgs);
403   FIXCHAR(filename,len,t1);
404   *ierr = PetscOptionsInsert(&PetscGlobalArgc,&PetscGlobalArgs,t1);
405   FREECHAR(filename,t1);
406   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating options database\n");return;}
407   *ierr = PetscOptionsCheckInitial_Private();
408   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Checking initial options\n");return;}
409 #if defined(PETSC_USE_LOG)
410   *ierr = PetscLogBegin_Private();
411   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize: intializing logging\n");return;}
412 #endif
413   *ierr = PetscInitialize_DynamicLibraries();
414   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Initializing dynamic libraries\n");return;}
415 
416   *ierr = PetscInitializeFortran();
417   if (*ierr) { (*PetscErrorPrintf)("PetscInitialize:Setting up common block\n");return;}
418 
419   *ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);
420   if (*ierr) { (*PetscErrorPrintf)("PetscInitialize:Getting MPI_Comm_size()\n");return;}
421   *ierr = PetscInfo1(0,"(Fortran):PETSc successfully started: procs %d\n",size);
422   if (*ierr) { (*PetscErrorPrintf)("PetscInitialize:Calling PetscInfo()\n");return;}
423   *ierr = PetscGetHostName(hostname,64);
424   if (*ierr) { (*PetscErrorPrintf)("PetscInitialize:Getting hostname\n");return;}
425   *ierr = PetscInfo1(0,"Running on machine: %s\n",hostname);
426   if (*ierr) { (*PetscErrorPrintf)("PetscInitialize:Calling PetscInfo()\n");return;}
427   *ierr = PetscOptionsCheckInitial_Components();
428   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Checking initial options\n");return;}
429 
430   *ierr = PetscThreadCommInitializePackage(NULL);
431   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Calling PetscThreadCommInitialize()\n");return;}
432 
433 #if defined(PETSC_USE_DEBUG)
434   PetscThreadLocalRegister((PetscThreadKey*)&petscstack); /* Creates petscstack_key if needed */
435   *ierr = PetscStackCreate();
436   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:PetscStackCreate()\n");return;}
437 #endif
438 
439   *ierr = PetscOptionsGetInt(NULL,"-hmpi_spawn_size",&nodesize,&flg);
440   if (flg) {
441 #if defined(PETSC_HAVE_MPI_COMM_SPAWN)
442     *ierr = PetscHMPISpawn((PetscMPIInt) nodesize); /* worker nodes never return from here; they go directly to PetscEnd() */
443     if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:PetscHMPIS-pawn()\n");return;}
444 #else
445     *ierr = PETSC_ERR_SUP;
446     (*PetscErrorPrintf)("PetscInitialize: PETSc built without MPI 2 (MPI_Comm_spawn) support, use -hmpi_merge_size instead");
447     return;
448 #endif
449   } else {
450     *ierr = PetscOptionsGetInt(NULL,"-hmpi_merge_size",&nodesize,&flg);
451     if (flg) {
452       *ierr = PetscHMPIMerge((PetscMPIInt) nodesize,NULL,NULL);
453       if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:PetscHMPIMerge()\n");return;}
454       if (PetscHMPIWorker) { /* if worker then never enter user code */
455         PetscInitializeCalled = PETSC_TRUE;
456         *ierr = PetscEnd();
457       }
458     }
459   }
460 
461 #if defined(PETSC_HAVE_CUDA)
462   cublasInit();
463 #endif
464 }
465 
466 void PETSC_STDCALL petscfinalize_(PetscErrorCode *ierr)
467 {
468 #if defined(PETSC_HAVE_SUNMATHPRO)
469   extern void standard_arithmetic();
470   standard_arithmetic();
471 #endif
472   /* was malloced with PetscMallocAlign() so free the same way */
473   *ierr = PetscFreeAlign(PetscGlobalArgs,0,0,0,0);if (*ierr) {(*PetscErrorPrintf)("PetscFinalize:Freeing args\n");return;}
474 
475   *ierr = PetscFinalize();
476 }
477 
478 void PETSC_STDCALL petscend_(PetscErrorCode *ierr)
479 {
480 #if defined(PETSC_HAVE_SUNMATHPRO)
481   extern void standard_arithmetic();
482   standard_arithmetic();
483 #endif
484 
485   *ierr = PetscEnd();
486 }
487 
488 
489 EXTERN_C_END
490