1 // -*- C++ -*-
2 
3 // Debug.h - helps debugging.
4 
5 // If ASAPDEBUG is set in Asap.h, all functions print debugging info.
6 //
7 // If ASAPDEBUG is not set in Asap.h, but is set in a .cpp file just
8 // before including this header, methods in that file print debugging
9 // info.
10 //
11 // If DEBUGOBJECTS is set in Asap.h, debugging messages are printed
12 // when central objects are created or destroyed.
13 //
14 // If ASAPMEMORYDEBUG is set in Asap.h or in a .cpp file just before
15 // including this header, memory usage is printed when MEMORY is
16 // called.
17 //
18 //
19 // Copyright (C) 2008-2011 Jakob Schiotz and Center for Individual
20 // Nanoparticle Functionality, Department of Physics, Technical
21 // University of Denmark.  Email: schiotz@fysik.dtu.dk
22 //
23 // This file is part of Asap version 3.
24 // Asap is released under the GNU Lesser Public License (LGPL) version 3.
25 // However, the parts of Asap distributed within the OpenKIM project
26 // (including this file) are also released under the Common Development
27 // and Distribution License (CDDL) version 1.0.
28 //
29 // This program is free software: you can redistribute it and/or
30 // modify it under the terms of the GNU Lesser General Public License
31 // version 3 as published by the Free Software Foundation.  Permission
32 // to use other versions of the GNU Lesser General Public License may
33 // granted by Jakob Schiotz or the head of department of the
34 // Department of Physics, Technical University of Denmark, as
35 // described in section 14 of the GNU General Public License.
36 //
37 // This program is distributed in the hope that it will be useful,
38 // but WITHOUT ANY WARRANTY; without even the implied warranty of
39 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
40 // GNU General Public License for more details.
41 //
42 // You should have received a copy of the GNU General Public License
43 // and the GNU Lesser Public License along with this program.  If not,
44 // see <http://www.gnu.org/licenses/>.
45 
46 
47 #ifndef _DEBUG_H
48 #define _DEBUG_H
49 
50 namespace ASAPSPACE {
51 
52 #ifdef ASAPDEBUG
53 
54 #ifdef _OPENMP
55 #include <omp.h>
56 #define OPENMPTHR << omp_get_thread_num() << " "
57 #else
58 #define OPENMPTHR
59 #endif
60 
61 #ifdef __GNUC__
62 #define DEBUGPRINT std::cerr OPENMPTHR << "Now in " << __PRETTY_FUNCTION__ << " (" << __FILE__ << ":" << __LINE__ << ")" << std::endl << std::flush;
63 #else // __GNUC__
64 #define DEBUGPRINT std::cerr OPENMPTHR << "Now in " << __FILE__ << ":" << __LINE__ << std::endl << std::flush;
65 #endif // __GNUC_
66 
67 #else  //ASAPDEBUG
68 
69 #define DEBUGPRINT
70 
71 #endif //ASAPDEBUG
72 
73 
74 
75 
76 
77 #ifdef DEBUGOBJECTS
78 
79 #ifdef __GNUC__
80 #define CONSTRUCTOR std::cerr << "Constructing object: " << __PRETTY_FUNCTION__  << " " << __FILE__ << " (" << this << ")" << std::endl << std::flush;
81 #define DESTRUCTOR std::cerr << "Destroying object: " << __PRETTY_FUNCTION__ << " (" << this << ")" << std::endl << std::flush;
82 #else // __GNUC__
83 #define CONSTRUCTOR std::cerr << "Constructing object: " << __FILE__ << ":" << __LINE__ << " (" << this << ")" << std::endl << std::flush;
84 #define DESTRUCTOR std::cerr << "Destroying object: " << __FILE__ << ":" << __LINE__ << " (" << this << ")" << std::endl << std::flush;
85 #endif // __GNUC_
86 
87 #else // DEBUGOBJECTS
88 
89 #define CONSTRUCTOR
90 #define DESTRUCTOR
91 
92 #endif // DEBUGOBJECTS
93 
94 
95 #ifdef ASAPMEMORYDEBUG
96 
97 void AsapPrintMemory(const char *file, int line);
98 #define MEMORY AsapPrintMemory(__FILE__, __LINE__)
99 
100 #else // ASAPMEMORYDEBUG
101 
102 #define MEMORY
103 
104 #endif // ASAPMEMORYDEBUG
105 
106 
107 /* get heap memory using mallinfo.
108    There is a UNIX version and a Mac OS X version is not well tested
109    but seems to give credible values in simple tests.*/
110 
111 double heap_mallinfo();
112 
113 } // end namespace
114 
115 #else // _DEBUG_H
116 
117 #warning "Multiple inclusion of Debug.h"
118 
119 #endif // _DEBUG_H
120