xref: /petsc/src/sys/memory/ftn-custom/zmtrf.c (revision fbe7908bcbdc335e0dab871e0aba2fea2d749384)
1 #include <petsc-private/fortranimpl.h>
2 #include <petscsys.h>
3 #include <petscviewer.h>
4 
5 #if defined(PETSC_HAVE_FORTRAN_CAPS)
6 #define petscmallocdump_           PETSCMALLOCDUMP
7 #define petscmallocdumplog_        PETSCMALLOCDUMPLOG
8 #define petscmallocvalidate_       PETSCMALLOCVALIDATE
9 #define petscmemoryshowusage_      PETSCMEMORYSHOWUSAGE
10 #define petscmemorysetgetmaximumusage_ PETSCMEMORYSETGETMAXIMUMUSAGE
11 #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
12 #define petscmallocdump_           petscmallocdump
13 #define petscmallocdumplog_        petscmallocdumplog
14 #define petscmallocvalidate_       petscmallocvalidate
15 #define petscmemoryshowusage_      petscmemoryshowusage
16 #define petscmemorysetgetmaximumusage_ petscmemorysetgetmaximumusage
17 #endif
18 
19 EXTERN_C_BEGIN
20 
21 #undef __FUNCT__
22 #define __FUNCT__ "PetscFixSlashN"
23 static PetscErrorCode PetscFixSlashN(const char *in, char **out)
24 {
25   PetscErrorCode ierr;
26   PetscInt       i;
27   size_t         len;
28 
29   PetscFunctionBegin;
30   ierr = PetscStrallocpy(in,out);CHKERRQ(ierr);
31   ierr = PetscStrlen(*out,&len);CHKERRQ(ierr);
32   for (i=0; i<(int)len-1; i++) {
33     if ((*out)[i] == '\\' && (*out)[i+1] == 'n') {(*out)[i] = ' '; (*out)[i+1] = '\n';}
34   }
35   PetscFunctionReturn(0);
36 }
37 
38 void PETSC_STDCALL  petscmallocdump_(PetscErrorCode *ierr)
39 {
40   *ierr = PetscMallocDump(stdout);
41 }
42 void PETSC_STDCALL petscmallocdumplog_(PetscErrorCode *ierr)
43 {
44   *ierr = PetscMallocDumpLog(stdout);
45 }
46 
47 void PETSC_STDCALL petscmallocvalidate_(PetscErrorCode *ierr)
48 {
49   *ierr = PetscMallocValidate(0,"Unknown Fortran",0,0);
50 }
51 
52 void PETSC_STDCALL petscmemorysetgetmaximumusage_(PetscErrorCode *ierr)
53 {
54   *ierr = PetscMemorySetGetMaximumUsage();
55 }
56 
57 void PETSC_STDCALL petscmemoryshowusage_(PetscViewer *vin, CHAR message PETSC_MIXED_LEN(len), PetscErrorCode *ierr PETSC_END_LEN(len))
58 {
59   PetscViewer v;
60   char        *msg, *tmp;
61 
62   FIXCHAR(message,len,msg);
63   *ierr = PetscFixSlashN(msg,&tmp);if (*ierr) return;
64   PetscPatchDefaultViewers_Fortran(vin,v);
65   *ierr = PetscMemoryShowUsage(v,tmp);
66   FREECHAR(message,msg);
67 }
68 
69 EXTERN_C_END
70