File: PrintMemory.c

package info (click to toggle)
openmx 3.7.6-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 325,856 kB
  • ctags: 3,575
  • sloc: ansic: 152,655; f90: 2,080; python: 876; makefile: 675; sh: 25; perl: 18
file content (74 lines) | stat: -rw-r--r-- 1,489 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**********************************************************************
  PrintMemory.c:

     PrintMemory.c is a subroutine to save memory size of each array.

  Log of PrintMemory.c:

     13/Mar/2003  Released by H. Kino
     14/Oct/2011  Rewritten by T.Ozaki

***********************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "openmx_common.h"

static void PrintMemory_Output(char *name, long int size0, char *mode);

void PrintMemory(char *name, long int size0, char *mode)
{

  if (memoryusage_fileout){
    PrintMemory_Output(name, size0, mode);
  }
}


void PrintMemory_Output(char *name, long int size0, char *mode)
{
  FILE *fp;
  double size;
  static char *filename;
  static long double sumsize;

  if (mode!=NULL) {

    /* initialization */

    if (strcmp(mode,"init")==0) {

      sumsize = 0.0; 
      filename = name;
      fp = fopen(filename,"w");

      if (fp==NULL) {
	printf("PrintMemory: fail to open a file: %s\n",name);
      }
      else {
	fclose(fp);
      }

      return;
    }

    /* summation of memory */

    if (strcmp(mode,"sum")==0) {
      fp = fopen(filename,"a");
      fprintf(fp,"Memory: %-45s %10.2f MBytes\n","total",(double)sumsize);
      fclose(fp);
      return;
    }
  }

  /* add data to the file */

  size = (double)size0/(1024*1024);
  sumsize += size;
  fp = fopen(filename,"a");
  fprintf(fp,"Memory: %-45s %10.2f MBytes\n",name,size);
  fclose(fp);

}