xref: /petsc/include/petsc.h (revision f26ada1b813e5274d9a7a57fff8541d305429fd7)
1*f26ada1bSBarry Smith /* $Id: petsc.h,v 1.69 1995/11/15 20:07:20 curfman Exp bsmith $ */
2*f26ada1bSBarry Smith /*
3*f26ada1bSBarry Smith    PETSc header file, included in all PETSc programs.
4*f26ada1bSBarry Smith */
52eac72dbSBarry Smith #if !defined(__PETSC_PACKAGE)
62eac72dbSBarry Smith #define __PETSC_PACKAGE
72eac72dbSBarry Smith 
836ab9709SLois Curfman McInnes #define PETSC_VERSION_NUMBER "PETSc Version 2.0.Beta.10, Released ?."
97e59f0e8SBarry Smith 
10f0479e8cSBarry Smith #include <stdio.h>
11416022c9SBarry Smith #if defined(PARCH_sun4) && !defined(__cplusplus)
12416022c9SBarry Smith extern int fprintf(FILE*,const char*,...);
13416022c9SBarry Smith extern int printf(const char*,...);
14416022c9SBarry Smith extern int fflush(FILE *);
15b1de499dSLois Curfman McInnes extern int fclose(FILE *);
16b1de499dSLois Curfman McInnes extern void fscanf(FILE *,char *,...);
1728988994SBarry Smith #endif
18f0479e8cSBarry Smith 
19f0479e8cSBarry Smith /* MPI interface */
20f0479e8cSBarry Smith #include "mpi.h"
217f813858SBarry Smith #include "mpiu.h"
22f0479e8cSBarry Smith 
23c6a45a97SBarry Smith #if defined(PETSC_COMPLEX)
24c6a45a97SBarry Smith /* work around for bug in alpha g++ compiler */
25c6a45a97SBarry Smith #if defined(PARCH_alpha)
26c6a45a97SBarry Smith #define hypot(a,b) (double) sqrt((a)*(a)+(b)*(b))
27c6a45a97SBarry Smith #endif
288ed539a5SBarry Smith #include <complex.h>
2920563c6bSBarry Smith #define PETSCREAL(a) real(a)
308ed539a5SBarry Smith #define Scalar       complex
318ed539a5SBarry Smith #else
3220563c6bSBarry Smith #define PETSCREAL(a) a
338ed539a5SBarry Smith #define Scalar       double
348ed539a5SBarry Smith #endif
358ed539a5SBarry Smith 
36d90ea2a1SBarry Smith extern void *(*PetscMalloc)(unsigned int,int,char*);
37d90ea2a1SBarry Smith extern int  (*PetscFree)(void *,int,char*);
380452661fSBarry Smith #define PetscMalloc(a)       (*PetscMalloc)(a,__LINE__,__FILE__)
39*f26ada1bSBarry Smith #define PetscNew(A)          (A*) PetscMalloc(sizeof(A))
400452661fSBarry Smith #define PetscFree(a)         (*PetscFree)(a,__LINE__,__FILE__)
41416022c9SBarry Smith extern int  PetscSetMalloc(void *(*)(unsigned int,int,char*),int (*)(void *,int,char*));
42c7485abaSBarry Smith extern int  TrDump(FILE *);
43e9f47e53SBarry Smith extern int  TrGetMaximumAllocated(double*);
448ed539a5SBarry Smith 
45416022c9SBarry Smith extern void  PetscMemcpy(void *,void *,int);
46cddf8d76SBarry Smith extern void  PetscMemzero(void *,int);
47416022c9SBarry Smith extern int   PetscStrlen(char *);
48416022c9SBarry Smith extern int   PetscStrcmp(char *,char *);
49416022c9SBarry Smith extern int   PetscStrncmp(char *,char *,int );
50416022c9SBarry Smith extern void  PetscStrcpy(char *,char *);
51416022c9SBarry Smith extern void  PetscStrcat(char *,char *);
52416022c9SBarry Smith extern void  PetscStrncat(char *,char *,int);
53416022c9SBarry Smith extern void  PetscStrncpy(char *,char *,int);
54416022c9SBarry Smith extern char* PetscStrchr(char *,char);
55416022c9SBarry Smith extern char* PetscStrrchr(char *,char);
56416022c9SBarry Smith extern char* PetscStrstr(char*,char*);
57416022c9SBarry Smith extern char* PetscStrtok(char*,char*);
58416022c9SBarry Smith extern char* PetscStrrtok(char*,char*);
5941d1187eSSatish Balay extern int   PetscMemcmp(char*, char*, int);
602eac72dbSBarry Smith 
610452661fSBarry Smith #define PetscMin(a,b)      ( ((a)<(b)) ? (a) : (b) )
620452661fSBarry Smith #define PetscMax(a,b)      ( ((a)<(b)) ? (b) : (a) )
63cddf8d76SBarry Smith #define PetscAbsInt(a)     ( ((a)<0)   ? -(a) : (a) )
64cddf8d76SBarry Smith 
65cddf8d76SBarry Smith #if defined(PETSC_COMPLEX)
66cddf8d76SBarry Smith #define PetscAbsScalar(a)     abs(a)
67cddf8d76SBarry Smith #else
68cddf8d76SBarry Smith #define PetscAbsScalar(a)     ( ((a)<0.0)   ? -(a) : (a) )
69cddf8d76SBarry Smith #endif
70145fe58dSBarry Smith 
712eac72dbSBarry Smith /*  Macros for error checking */
72f0479e8cSBarry Smith #if !defined(__DIR__)
73f0479e8cSBarry Smith #define __DIR__ 0
74f0479e8cSBarry Smith #endif
75d636dbe3SBarry Smith 
76d636dbe3SBarry Smith /*
77d636dbe3SBarry Smith        Unable to malloc error and no supported function
78d636dbe3SBarry Smith */
79416022c9SBarry Smith #define PETSC_ERR_MEM 55   /* unable to allocate requested memory */
80dbb450caSBarry Smith #define PETSC_ERR_SUP 56   /* no support yet for this operation */
81dbb450caSBarry Smith #define PETSC_ERR_ARG 57   /* bad input argument */
82dbb450caSBarry Smith #define PETSC_ERR_OBJ 58   /* null or corrupt PETSc object */
83d636dbe3SBarry Smith 
8428988994SBarry Smith #if defined(PETSC_DEBUG)
851987afe7SBarry Smith #define SETERRQ(n,s)     {return PetscError(__LINE__,__DIR__,__FILE__,n,s);}
861987afe7SBarry Smith #define SETERRA(n,s)     {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\
87d6dfbf8fSBarry Smith                           MPI_Abort(MPI_COMM_WORLD,_ierr);}
8878b31e54SBarry Smith #define CHKERRQ(n)       {if (n) SETERRQ(n,(char *)0);}
89d6dfbf8fSBarry Smith #define CHKERRA(n)       {if (n) SETERRA(n,(char *)0);}
90d636dbe3SBarry Smith #define CHKPTRQ(p)       if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0);
91d636dbe3SBarry Smith #define CHKPTRA(p)       if (!p) SETERRA(PETSC_ERR_MEM,(char*)0);
9228988994SBarry Smith #else
931987afe7SBarry Smith #define SETERRQ(n,s)     {return PetscError(__LINE__,__DIR__,__FILE__,n,s);}
941987afe7SBarry Smith #define SETERRA(n,s)     {int _ierr = PetscError(__LINE__,__DIR__,__FILE__,n,s);\
9528988994SBarry Smith                           MPI_Abort(MPI_COMM_WORLD,_ierr);}
9678b31e54SBarry Smith #define CHKERRQ(n)       {if (n) SETERRQ(n,(char *)0);}
9728988994SBarry Smith #define CHKERRA(n)       {if (n) SETERRA(n,(char *)0);}
98d636dbe3SBarry Smith #define CHKPTRQ(p)       if (!p) SETERRQ(PETSC_ERR_MEM,(char*)0);
99d636dbe3SBarry Smith #define CHKPTRA(p)       if (!p) SETERRA(PETSC_ERR_MEM,(char*)0);
10028988994SBarry Smith #endif
1012eac72dbSBarry Smith 
1028ed539a5SBarry Smith typedef struct _PetscObject* PetscObject;
1031a941147SBarry Smith #define PETSC_COOKIE         1211211
1046b5873e3SBarry Smith #define PETSC_DECIDE         -1
10555b5a45fSLois Curfman McInnes #define PETSC_DEFAULT        -2
106da69df5fSBarry Smith 
107ca9b4cbeSLois Curfman McInnes typedef enum { PETSC_FALSE, PETSC_TRUE } PetscTruth;
108ca9b4cbeSLois Curfman McInnes 
109da69df5fSBarry Smith #include "viewer.h"
1108c8d4905SLois Curfman McInnes #include "options.h"
1112eac72dbSBarry Smith 
112416022c9SBarry Smith extern int PetscInitialize(int*,char***,char*,char*,char*);
113a0a59b22SBarry Smith extern int PetscFinalize();
114a0a59b22SBarry Smith 
115c60448a5SBarry Smith extern int PetscObjectDestroy(PetscObject);
1168f4c47bcSLois Curfman McInnes extern int PetscObjectExists(PetscObject,int*);
1177f223b93SBarry Smith extern int PetscObjectGetComm(PetscObject,MPI_Comm *comm);
118cddf8d76SBarry Smith extern int PetscObjectGetCookie(PetscObject,int *cookie);
119cddf8d76SBarry Smith extern int PetscObjectGetType(PetscObject,int *type);
120a5a9c739SBarry Smith extern int PetscObjectSetName(PetscObject,char*);
121a5a9c739SBarry Smith extern int PetscObjectGetName(PetscObject,char**);
1222eac72dbSBarry Smith 
1231987afe7SBarry Smith extern int PetscDefaultErrorHandler(int,char*,char*,int,char*,void*);
1241987afe7SBarry Smith extern int PetscAbortErrorHandler(int,char*,char*,int,char*,void* );
1251987afe7SBarry Smith extern int PetscAttachDebuggerErrorHandler(int,char*,char*,int,char*,void*);
1261987afe7SBarry Smith extern int PetscError(int,char*,char*,int,char*);
1271987afe7SBarry Smith extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,int,char*,void*),void*);
1288ed539a5SBarry Smith extern int PetscPopErrorHandler();
1298ed539a5SBarry Smith 
1308ed539a5SBarry Smith extern int PetscSetDebugger(char *,int,char *);
1318ed539a5SBarry Smith extern int PetscAttachDebugger();
1328ed539a5SBarry Smith 
133f0479e8cSBarry Smith extern int PetscDefaultSignalHandler(int,void*);
134f0479e8cSBarry Smith extern int PetscPushSignalHandler(int (*)(int,void *),void*);
135f0479e8cSBarry Smith extern int PetscPopSignalHandler();
136f0479e8cSBarry Smith extern int PetscSetFPTrap(int);
1376b5873e3SBarry Smith #define FP_TRAP_OFF    0
1386b5873e3SBarry Smith #define FP_TRAP_ON     1
139fba13676SBarry Smith #define FP_TRAP_ALWAYS 2
1408ed539a5SBarry Smith 
14131b41497SLois Curfman McInnes /*
14231b41497SLois Curfman McInnes    Definitions used for the Fortran interface:
14331b41497SLois Curfman McInnes    FORTRANCAPS:       Names are uppercase, no trailing underscore
14431b41497SLois Curfman McInnes    FORTRANUNDERSCORE: Names are lowercase, trailing underscore
14531b41497SLois Curfman McInnes  */
146602c2b74SBarry Smith #if defined(PARCH_cray) || defined(PARCH_NCUBE) || defined(PARCH_t3d)
1478ed539a5SBarry Smith #define FORTRANCAPS
148d90ea2a1SBarry Smith #elif !defined(PARCH_rs6000) && !defined(PARCH_NeXT) && !defined(PARCH_hpux)
1498ed539a5SBarry Smith #define FORTRANUNDERSCORE
1502eac72dbSBarry Smith #endif
1512eac72dbSBarry Smith 
15219b02663SBarry Smith #include "phead.h"
15319b02663SBarry Smith #include "plog.h"
1547857610eSBarry Smith 
1557ec12d72SBarry Smith extern void PetscSleep(int);
1567ec12d72SBarry Smith 
1572eac72dbSBarry Smith #endif
158