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 #include <petsc/private/fortranimpl.h> 15 16 #if defined(PETSC_HAVE_FORTRAN_CAPS) 17 #define petscinitializef_ PETSCINITIALIZEF 18 #define petscfinalize_ PETSCFINALIZE 19 #define petscend_ PETSCEND 20 #define iargc_ IARGC 21 #define getarg_ GETARG 22 #define mpi_init_ MPI_INIT 23 #define petscgetcomm_ PETSCGETCOMM 24 #define petsccommandargumentcount_ PETSCCOMMANDARGUMENTCOUNT 25 #define petscgetcommandargument_ PETSCGETCOMMANDARGUMENT 26 #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE) 27 #define petscinitializef_ petscinitializef 28 #define petscfinalize_ petscfinalize 29 #define petscend_ petscend 30 #define mpi_init_ mpi_init 31 #define iargc_ iargc 32 #define getarg_ getarg 33 #define petscgetcomm_ petscgetcomm 34 #define petsccommandargumentcount_ petsccommandargumentcount 35 #define petscgetcommandargument_ petscgetcommandargument 36 #endif 37 38 #if defined(PETSC_HAVE_NAGF90) 39 #undef iargc_ 40 #undef getarg_ 41 #define iargc_ f90_unix_MP_iargc 42 #define getarg_ f90_unix_MP_getarg 43 #endif 44 #if defined(PETSC_USE_NARGS) /* Digital Fortran */ 45 #undef iargc_ 46 #undef getarg_ 47 #define iargc_ NARGS 48 #define getarg_ GETARG 49 #elif defined(PETSC_HAVE_PXFGETARG_NEW) /* cray x1 */ 50 #undef iargc_ 51 #undef getarg_ 52 #define iargc_ ipxfargc_ 53 #define getarg_ pxfgetarg_ 54 #endif 55 #if defined(PETSC_HAVE_FORTRAN_IARGC_UNDERSCORE) /* HPUX + no underscore */ 56 #undef iargc_ 57 #undef getarg_ 58 #define iargc_ iargc_ 59 #define getarg_ getarg_ 60 #endif 61 62 #if defined(PETSC_HAVE_FORTRAN_GET_COMMAND_ARGUMENT) /* Fortran 2003 */ 63 #undef iargc_ 64 #undef getarg_ 65 #define iargc_ petsccommandargumentcount_ 66 #define getarg_ petscgetcommandargument_ 67 #elif 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 #define mpi_init_ mpi_init__ 86 #endif 87 88 #if defined(PETSC_HAVE_MPIUNI) 89 #if defined(mpi_init_) 90 #undef mpi_init_ 91 #if defined(PETSC_HAVE_FORTRAN_CAPS) 92 #define mpi_init_ PETSC_MPI_INIT 93 #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE) 94 #define mpi_init_ petsc_mpi_init 95 #elif defined(PETSC_HAVE_FORTRAN_UNDERSCORE_UNDERSCORE) 96 #define mpi_init_ petsc_mpi_init__ 97 #endif 98 #else /* mpi_init_ */ 99 #define mpi_init_ petsc_mpi_init_ 100 #endif /* mpi_init_ */ 101 #endif /* PETSC_HAVE_MPIUNI */ 102 103 PETSC_EXTERN void mpi_init_(int*); 104 PETSC_EXTERN void petscgetcomm_(PetscMPIInt*); 105 106 /* 107 Different Fortran compilers handle command lines in different ways 108 */ 109 #if defined(PETSC_HAVE_FORTRAN_GET_COMMAND_ARGUMENT) /* Fortran 2003 - same as 'else' case */ 110 PETSC_EXTERN int iargc_(void); 111 PETSC_EXTERN void getarg_(int*,char*,int); 112 #elif defined(PETSC_USE_NARGS) 113 PETSC_EXTERN short __stdcall NARGS(); 114 PETSC_EXTERN void __stdcall GETARG(short*,char*,int,short *); 115 116 #elif defined(PETSC_HAVE_PXFGETARG_NEW) 117 PETSC_EXTERN int iargc_(); 118 PETSC_EXTERN void getarg_(int*,char*,int*,int*,int); 119 120 #else 121 PETSC_EXTERN int iargc_(); 122 PETSC_EXTERN void getarg_(int*,char*,int); 123 /* 124 The Cray T3D/T3E use the PXFGETARG() function 125 */ 126 #if defined(PETSC_HAVE_PXFGETARG) 127 PETSC_EXTERN void PXFGETARG(int*,_fcd,int*,int*); 128 #endif 129 #endif 130 131 #if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16) 132 PETSC_EXTERN void MPIAPI PetscSum_Local(void*,void*,PetscMPIInt*,MPI_Datatype*); 133 PETSC_EXTERN void MPIAPI PetscMax_Local(void*,void*,PetscMPIInt*,MPI_Datatype*); 134 PETSC_EXTERN void MPIAPI PetscMin_Local(void*,void*,PetscMPIInt*,MPI_Datatype*); 135 #endif 136 137 PETSC_INTERN void MPIAPI MPIU_MaxSum_Local(void*,void*,PetscMPIInt*,MPI_Datatype*); 138 PETSC_EXTERN PetscMPIInt MPIAPI Petsc_Counter_Attr_Delete_Fn(MPI_Comm,PetscMPIInt,void*,void*); 139 PETSC_EXTERN PetscMPIInt MPIAPI Petsc_InnerComm_Attr_Delete_Fn(MPI_Comm,PetscMPIInt,void*,void*); 140 PETSC_EXTERN PetscMPIInt MPIAPI Petsc_OuterComm_Attr_Delete_Fn(MPI_Comm,PetscMPIInt,void*,void*); 141 142 PETSC_INTERN PetscErrorCode PetscOptionsCheckInitial_Private(const char[]); 143 PETSC_INTERN PetscErrorCode PetscInitialize_DynamicLibraries(void); 144 #if defined(PETSC_USE_LOG) 145 PETSC_INTERN PetscErrorCode PetscLogInitialize(void); 146 #endif 147 PETSC_EXTERN PetscErrorCode PetscMallocAlign(size_t,PetscBool,int,const char[],const char[],void**); 148 PETSC_EXTERN PetscErrorCode PetscFreeAlign(void*,int,const char[],const char[]); 149 PETSC_INTERN int PetscGlobalArgc; 150 PETSC_INTERN char **PetscGlobalArgs; 151 152 /* 153 Reads in Fortran command line argments and sends them to 154 all processors. 155 */ 156 157 PetscErrorCode PETScParseFortranArgs_Private(int *argc,char ***argv) 158 { 159 #if defined(PETSC_USE_NARGS) 160 short i,flg; 161 #else 162 int i; 163 #endif 164 PetscErrorCode ierr; 165 int warg = 256; 166 PetscMPIInt rank; 167 char *p; 168 169 ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRMPI(ierr); 170 if (!rank) { 171 #if defined(PETSC_HAVE_IARG_COUNT_PROGNAME) 172 *argc = iargc_(); 173 #else 174 /* most compilers do not count the program name for argv[0] */ 175 *argc = 1 + iargc_(); 176 #endif 177 } 178 ierr = MPI_Bcast(argc,1,MPI_INT,0,PETSC_COMM_WORLD);CHKERRMPI(ierr); 179 180 /* PetscTrMalloc() not yet set, so don't use PetscMalloc() */ 181 ierr = PetscMallocAlign((*argc+1)*(warg*sizeof(char)+sizeof(char*)),PETSC_FALSE,0,0,0,(void**)argv);CHKERRQ(ierr); 182 (*argv)[0] = (char*)(*argv + *argc + 1); 183 184 if (!rank) { 185 ierr = PetscMemzero((*argv)[0],(*argc)*warg*sizeof(char));CHKERRQ(ierr); 186 for (i=0; i<*argc; i++) { 187 (*argv)[i+1] = (*argv)[i] + warg; 188 #if defined (PETSC_HAVE_FORTRAN_GET_COMMAND_ARGUMENT) /* same as 'else' case */ 189 getarg_(&i,(*argv)[i],warg); 190 #elif defined(PETSC_HAVE_PXFGETARG_NEW) 191 {char *tmp = (*argv)[i]; 192 int ilen; 193 getarg_(&i,tmp,&ilen,&ierr,warg);CHKERRQ(ierr); 194 tmp[ilen] = 0;} 195 #elif defined(PETSC_USE_NARGS) 196 GETARG(&i,(*argv)[i],warg,&flg); 197 #else 198 /* 199 Because the stupid #defines above define all kinds of things to getarg_ we cannot do this test 200 #elif defined(PETSC_HAVE_GETARG) 201 getarg_(&i,(*argv)[i],warg); 202 #else 203 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot get Fortran command line arguments"); 204 */ 205 getarg_(&i,(*argv)[i],warg); 206 #endif 207 /* zero out garbage at end of each argument */ 208 p = (*argv)[i] + warg-1; 209 while (p > (*argv)[i]) { 210 if (*p == ' ') *p = 0; 211 p--; 212 } 213 } 214 } 215 ierr = MPI_Bcast((*argv)[0],*argc*warg,MPI_CHAR,0,PETSC_COMM_WORLD);CHKERRMPI(ierr); 216 if (rank) { 217 for (i=0; i<*argc; i++) (*argv)[i+1] = (*argv)[i] + warg; 218 } 219 return 0; 220 } 221 222 #if defined(PETSC_SERIALIZE_FUNCTIONS) 223 PETSC_INTERN PetscFPT PetscFPTData; 224 #endif 225 226 #if defined(PETSC_HAVE_ADIOS) 227 #include <adios.h> 228 #include <adios_read.h> 229 #endif 230 /* -----------------------------------------------------------------------------------------------*/ 231 232 #if defined(PETSC_HAVE_SAWS) 233 #include <petscviewersaws.h> 234 PETSC_INTERN PetscErrorCode PetscInitializeSAWs(const char[]); 235 #endif 236 237 PETSC_EXTERN PetscMPIInt MPIAPI Petsc_ShmComm_Attr_Delete_Fn(MPI_Comm,PetscMPIInt,void *,void *); 238 PETSC_INTERN PetscErrorCode PetscPreMPIInit_Private(); 239 240 /* 241 petscinitialize - Version called from Fortran. 242 243 Notes: 244 Since this is called from Fortran it does not return error codes 245 246 */ 247 PETSC_EXTERN void petscinitializef_(char* filename,char* help,PetscBool *readarguments,PetscErrorCode *ierr,PETSC_FORTRAN_CHARLEN_T len,PETSC_FORTRAN_CHARLEN_T helplen) 248 { 249 int j,i; 250 #if defined (PETSC_USE_NARGS) 251 short flg; 252 #endif 253 int flag; 254 PetscMPIInt size; 255 char *t1,name[256],hostname[64]; 256 PetscMPIInt f_petsc_comm_world; 257 258 *ierr = PetscMemzero(name,sizeof(name)); if (*ierr) return; 259 if (PetscInitializeCalled) {*ierr = 0; return;} 260 261 /* this must be initialized in a routine, not as a constant declaration*/ 262 PETSC_STDOUT = stdout; 263 PETSC_STDERR = stderr; 264 265 /* on Windows - set printf to default to printing 2 digit exponents */ 266 #if defined(PETSC_HAVE__SET_OUTPUT_FORMAT) 267 _set_output_format(_TWO_DIGIT_EXPONENT); 268 #endif 269 270 *ierr = PetscOptionsCreateDefault(); 271 if (*ierr) return; 272 i = 0; 273 #if defined (PETSC_HAVE_FORTRAN_GET_COMMAND_ARGUMENT) /* same as 'else' case */ 274 getarg_(&i,name,sizeof(name)); 275 #elif defined (PETSC_HAVE_PXFGETARG_NEW) 276 { int ilen,sierr; 277 getarg_(&i,name,&ilen,&sierr,256); 278 if (sierr) PetscStrncpy(name,"Unknown Name",256); 279 else name[ilen] = 0; 280 } 281 #elif defined(PETSC_USE_NARGS) 282 GETARG(&i,name,256,&flg); 283 #else 284 getarg_(&i,name,256); 285 #endif 286 /* Eliminate spaces at the end of the string */ 287 for (j=sizeof(name)-2; j>=0; j--) { 288 if (name[j] != ' ') { 289 name[j+1] = 0; 290 break; 291 } 292 } 293 if (j<0) PetscStrncpy(name,"Unknown Name",256); 294 *ierr = PetscSetProgramName(name); 295 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize: Calling PetscSetProgramName()\n");return;} 296 297 /* check if PETSC_COMM_WORLD is initialized by the user in fortran */ 298 petscgetcomm_(&f_petsc_comm_world); 299 MPI_Initialized(&flag); 300 if (!flag) { 301 PetscMPIInt mierr; 302 303 if (f_petsc_comm_world) {(*PetscErrorPrintf)("You cannot set PETSC_COMM_WORLD if you have not initialized MPI first\n");return;} 304 305 *ierr = PetscPreMPIInit_Private(); if (*ierr) return; 306 mpi_init_(&mierr); 307 if (mierr) { 308 *ierr = mierr; 309 (*PetscErrorPrintf)("PetscInitialize: Calling Fortran MPI_Init()\n"); 310 return; 311 } 312 PetscBeganMPI = PETSC_TRUE; 313 } 314 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 */ 315 else PETSC_COMM_WORLD = MPI_COMM_WORLD; 316 *ierr = MPI_Comm_set_errhandler(PETSC_COMM_WORLD,MPI_ERRORS_RETURN); 317 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize: Setting MPI error handler\n");return;} 318 PetscInitializeCalled = PETSC_TRUE; 319 320 *ierr = PetscSpinlockCreate(&PetscViewerASCIISpinLockOpen); 321 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize: Creating global spin lock\n");return;} 322 *ierr = PetscSpinlockCreate(&PetscViewerASCIISpinLockStdout); 323 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize: Creating global spin lock\n");return;} 324 *ierr = PetscSpinlockCreate(&PetscViewerASCIISpinLockStderr); 325 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize: Creating global spin lock\n");return;} 326 *ierr = PetscSpinlockCreate(&PetscCommSpinLock); 327 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize: Creating global spin lock\n");return;} 328 329 *ierr = PetscErrorPrintfInitialize(); 330 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize: Calling PetscErrorPrintfInitialize()\n");return;} 331 *ierr = MPI_Comm_rank(MPI_COMM_WORLD,&PetscGlobalRank); 332 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize: Setting PetscGlobalRank\n");return;} 333 *ierr = MPI_Comm_size(MPI_COMM_WORLD,&PetscGlobalSize); 334 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize: Setting PetscGlobalSize\n");return;} 335 336 MPIU_BOOL = MPI_INT; 337 MPIU_ENUM = MPI_INT; 338 MPIU_FORTRANADDR = (sizeof(void*) == sizeof(int)) ? MPI_INT : MPIU_INT64; 339 if (sizeof(size_t) == sizeof(unsigned)) MPIU_SIZE_T = MPI_UNSIGNED; 340 else if (sizeof(size_t) == sizeof(unsigned long)) MPIU_SIZE_T = MPI_UNSIGNED_LONG; 341 #if defined(PETSC_SIZEOF_LONG_LONG) 342 else if (sizeof(size_t) == sizeof(unsigned long long)) MPIU_SIZE_T = MPI_UNSIGNED_LONG_LONG; 343 #endif 344 else {(*PetscErrorPrintf)("PetscInitialize: Could not find MPI type for size_t\n"); return;} 345 346 #if defined(PETSC_HAVE_COMPLEX) 347 /* 348 Initialized the global variable; this is because with 349 shared libraries the constructors for global variables 350 are not called; at least on IRIX. 351 */ 352 { 353 #if defined(PETSC_CLANGUAGE_CXX) 354 PetscComplex ic(0.0,1.0); 355 PETSC_i = ic; 356 #else 357 PETSC_i = _Complex_I; 358 #endif 359 } 360 #endif 361 362 #if defined(PETSC_USE_REAL___FLOAT128) 363 *ierr = MPI_Type_contiguous(2,MPI_DOUBLE,&MPIU___FLOAT128); 364 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI types\n");return;} 365 *ierr = MPI_Type_commit(&MPIU___FLOAT128); 366 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI types\n");return;} 367 #if defined(PETSC_HAVE_COMPLEX) 368 *ierr = MPI_Type_contiguous(4,MPI_DOUBLE,&MPIU___COMPLEX128); 369 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI types\n");return;} 370 *ierr = MPI_Type_commit(&MPIU___COMPLEX128); 371 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI types\n");return;} 372 #endif 373 *ierr = MPI_Op_create(PetscSum_Local,1,&MPIU_SUM); 374 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI ops\n");return;} 375 *ierr = MPI_Op_create(PetscMax_Local,1,&MPIU_MAX); 376 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI ops\n");return;} 377 *ierr = MPI_Op_create(PetscMin_Local,1,&MPIU_MIN); 378 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI ops\n");return;} 379 #elif defined(PETSC_USE_REAL___FP16) 380 *ierr = MPI_Type_contiguous(2,MPI_CHAR,&MPIU___FP16); 381 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI types\n");return;} 382 *ierr = MPI_Type_commit(&MPIU___FP16); 383 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI types\n");return;} 384 *ierr = MPI_Op_create(PetscSum_Local,1,&MPIU_SUM); 385 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI ops\n");return;} 386 *ierr = MPI_Op_create(PetscMax_Local,1,&MPIU_MAX); 387 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI ops\n");return;} 388 *ierr = MPI_Op_create(PetscMin_Local,1,&MPIU_MIN); 389 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI ops\n");return;} 390 #endif 391 392 /* 393 Create the PETSc MPI reduction operator that sums of the first 394 half of the entries and maxes the second half. 395 */ 396 *ierr = MPI_Op_create(MPIU_MaxSum_Local,1,&MPIU_MAXSUM_OP); 397 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI ops\n");return;} 398 399 *ierr = MPI_Type_contiguous(2,MPIU_SCALAR,&MPIU_2SCALAR); 400 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI types\n");return;} 401 *ierr = MPI_Type_commit(&MPIU_2SCALAR); 402 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI types\n");return;} 403 #if defined(PETSC_USE_64BIT_INDICES) 404 *ierr = MPI_Type_contiguous(2,MPIU_INT,&MPIU_2INT); 405 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI types\n");return;} 406 *ierr = MPI_Type_commit(&MPIU_2INT); 407 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI types\n");return;} 408 #endif 409 *ierr = MPI_Comm_create_keyval(MPI_COMM_NULL_COPY_FN,Petsc_Counter_Attr_Delete_Fn,&Petsc_Counter_keyval,(void*)0); 410 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI keyvals\n");return;} 411 *ierr = MPI_Comm_create_keyval(MPI_COMM_NULL_COPY_FN,Petsc_InnerComm_Attr_Delete_Fn,&Petsc_InnerComm_keyval,(void*)0); 412 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI keyvals\n");return;} 413 *ierr = MPI_Comm_create_keyval(MPI_COMM_NULL_COPY_FN,Petsc_OuterComm_Attr_Delete_Fn,&Petsc_OuterComm_keyval,(void*)0); 414 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI keyvals\n");return;} 415 *ierr = MPI_Comm_create_keyval(MPI_COMM_NULL_COPY_FN,Petsc_ShmComm_Attr_Delete_Fn,&Petsc_ShmComm_keyval,(void*)0); 416 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating MPI keyvals\n");return;} 417 418 /* 419 PetscInitializeFortran() is called twice. Here it initializes 420 PETSC_NULL_CHARACTER_Fortran. Below it initializes the PETSC_VIEWERs. 421 The PETSC_VIEWERs have not been created yet, so they must be initialized 422 below. 423 */ 424 PetscInitializeFortran(); 425 if (*readarguments) { 426 PETScParseFortranArgs_Private(&PetscGlobalArgc,&PetscGlobalArgs); 427 FIXCHAR(filename,len,t1); 428 *ierr = PetscOptionsInsert(NULL,&PetscGlobalArgc,&PetscGlobalArgs,t1); 429 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Creating options database\n");return;} 430 FREECHAR(filename,t1); 431 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Freeing string in creating options database\n");return;} 432 } 433 *ierr = PetscOptionsCheckInitial_Private(help); 434 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Checking initial options\n");return;} 435 /* call a second time to check options database */ 436 *ierr = PetscErrorPrintfInitialize(); 437 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize: Calling PetscErrorPrintfInitialize()\n");return;} 438 *ierr = PetscCitationsInitialize(); 439 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:PetscCitationsInitialize()\n");return;} 440 #if defined(PETSC_HAVE_SAWS) 441 *ierr = PetscInitializeSAWs(NULL); 442 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Initializing SAWs\n");return;} 443 #endif 444 #if defined(PETSC_USE_LOG) 445 *ierr = PetscLogInitialize(); 446 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize: initializing logging\n");return;} 447 #endif 448 *ierr = PetscInitialize_DynamicLibraries(); 449 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Initializing dynamic libraries\n");return;} 450 451 *ierr = PetscInitializeFortran(); 452 if (*ierr) { (*PetscErrorPrintf)("PetscInitialize:Setting up common block\n");return;} 453 454 *ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size); 455 if (*ierr) { (*PetscErrorPrintf)("PetscInitialize:Getting MPI_Comm_size()\n");return;} 456 *ierr = PetscInfo1(0,"(Fortran):PETSc successfully started: procs %d\n",size); 457 if (*ierr) { (*PetscErrorPrintf)("PetscInitialize:Calling PetscInfo()\n");return;} 458 *ierr = PetscGetHostName(hostname,64); 459 if (*ierr) { (*PetscErrorPrintf)("PetscInitialize:Getting hostname\n");return;} 460 *ierr = PetscInfo1(0,"Running on machine: %s\n",hostname); 461 if (*ierr) { (*PetscErrorPrintf)("PetscInitialize:Calling PetscInfo()\n");return;} 462 463 #if defined(PETSC_USE_DEBUG) && !defined(PETSC_HAVE_THREADSAFETY) 464 *ierr = PetscStackCreate(); 465 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:PetscStackCreate()\n");return;} 466 #endif 467 468 #if defined(PETSC_SERIALIZE_FUNCTIONS) 469 *ierr = PetscFPTCreate(10000); 470 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:PetscFPTCreate()\n");return;} 471 #endif 472 #if defined(PETSC_HAVE_ADIOS) 473 *ierr = adios_init_noxml(PETSC_COMM_WORLD); 474 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:adios_init_noxml()\n");return;} 475 *ierr = adios_declare_group(&Petsc_adios_group,"PETSc","",adios_stat_default); 476 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:adios_declare_group()\n");return;} 477 *ierr = adios_select_method(Petsc_adios_group,"MPI","",""); 478 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:adios_select_method()\n");return;} 479 *ierr = adios_read_init_method(ADIOS_READ_METHOD_BP,PETSC_COMM_WORLD,""); 480 if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:adios_read_init_method()\n");return;} 481 #endif 482 } 483 484 PETSC_EXTERN void petscfinalize_(PetscErrorCode *ierr) 485 { 486 #if defined(PETSC_HAVE_SUNMATHPRO) 487 extern void standard_arithmetic(); 488 standard_arithmetic(); 489 #endif 490 /* was malloced with PetscMallocAlign() so free the same way */ 491 *ierr = PetscFreeAlign(PetscGlobalArgs,0,0,0);if (*ierr) {(*PetscErrorPrintf)("PetscFinalize:Freeing args\n");return;} 492 493 *ierr = PetscFinalize(); 494 } 495 496 PETSC_EXTERN void petscend_(PetscErrorCode *ierr) 497 { 498 #if defined(PETSC_HAVE_SUNMATHPRO) 499 extern void standard_arithmetic(); 500 standard_arithmetic(); 501 #endif 502 503 *ierr = PetscEnd(); 504 } 505 506