1!! Copyright (C) 2003-2006 M. Marques, A.
Castro, A.
Rubio, G. Bertsch
4!! it under the terms of the GNU General Public License as published by
8!! This
program is distributed
in the hope that it will be useful,
9!! but WITHOUT ANY
WARRANTY; without
even the implied warranty of
10!! MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License
for more details.
13!! You should have received a copy of the GNU General Public License
24! is defined). Otherwise it is merely a logical assertion that, when
fails,
25! prints
out the assertion
string, the
file, and the line. The subroutine
28# define ASSERT(expr) \
30 call assert_die(TOSTRING(expr), __FILE__, __LINE__)
36! a helpful error
if the allocation
or deallocation
fails. They also take care of
37! calling the memory profiler. The
"MY_DEALLOCATE" macro is only used
in this file;
38!
in the
code, one should use SAFE_DEALLOCATE_P
for pointers and SAFE_DEALLOCATE_A
40! A special
version of the SAFE_ALLOCATE macro named SAFE_ALLOCATE_TYPE is also
41! provided to allocate a polymorphic variable. This is necessary because of the
42! special Fortran syntax
"type::var".
44# define SAFE_ALLOCATE(x) allocate(x)
46# define SAFE_ALLOCATE_TYPE(type, x) allocate(type::x)
48# define SAFE_ALLOCATE_TYPE_ARRAY(type, x, bounds) allocate(type::x bounds)
50# define SAFE_ALLOCATE_SOURCE(x, y) \
51 allocate(x, source=y);
53# define SAFE_ALLOCATE_SOURCE_A(x, y) \
54 if(allocated(y)) then; \
55 allocate(x, source=y); \
58# define SAFE_ALLOCATE_SOURCE_P(x, y) \
59 if(associated(y)) then; \
60 allocate(x, source=y); \
65# define SAFE_DEALLOCATE_P(x) \
66 if(associated(x)) then; \
70# define SAFE_DEALLOCATE_A(x) \
71 if(allocated(x)) then; \
76# define SAFE_ALLOCATE_PROFILE(x) \
77 if(global_alloc_err.ne.0) call alloc_error(global_alloc_errmsg, "allocate", __FILE__, __LINE__); \
78 if(not_in_openmp() .and. iand(prof_vars%mode, PROFILING_MEMORY).ne.0) \
79 call profiling_memory_allocate(TOSTRING(x), __FILE__, __LINE__, int(sizeof(x), int64));
81# define SAFE_ALLOCATE(x) \
82 allocate(x, stat=global_alloc_err, errmsg=global_alloc_errmsg); \
83 SAFE_ALLOCATE_PROFILE(x)
85# define SAFE_ALLOCATE_TYPE(type, x) \
86 allocate(type::x, stat=global_alloc_err, errmsg=global_alloc_errmsg); \
87 SAFE_ALLOCATE_PROFILE(x)
89! Some versions of GCC have a bug
in the
sizeof() function such that the compiler crashes with a ICE
90! when passing a polymorphic variable to the function and
explicit array bounds are given.
91! The workaround is
not to pass the bounds to
sizeof. Otherwise we could just use SAFE_ALLOCATE_TYPE.
92# define SAFE_ALLOCATE_TYPE_ARRAY(type, x, bounds) \
98# define SAFE_ALLOCATE_SOURCE_P(x, y) \
99 if(associated(y)) then; \
100 allocate(x, source=y, stat=global_alloc_err, errmsg=global_alloc_errmsg); \
101 SAFE_ALLOCATE_PROFILE(x); \
106# define SAFE_ALLOCATE_SOURCE_A(x, y) \
107 if(allocated(y)) then; \
108 allocate(x, source=y, stat=global_alloc_err, errmsg=global_alloc_errmsg); \
109 SAFE_ALLOCATE_PROFILE(x); \
112# define SAFE_ALLOCATE_SOURCE(x, y) \
113 allocate(x, source=y, stat=global_alloc_err, errmsg=global_alloc_errmsg); \
114 SAFE_ALLOCATE_PROFILE(x);
116# define MY_DEALLOCATE(x) \
117 global_sizeof = sizeof(x) ; \
118 deallocate(x, stat=global_alloc_err, errmsg=global_alloc_errmsg); \
119 if(global_alloc_err.ne.0) call alloc_error(global_alloc_errmsg, "deallocate", __FILE__, __LINE__); \
120 if(not_in_openmp() .and. iand(prof_vars%mode, PROFILING_MEMORY).ne.0) \
121 call profiling_memory_deallocate(TOSTRING(x), __FILE__, __LINE__, global_sizeof);
123# define SAFE_DEALLOCATE_P(x) \
124 if(associated(x)) then; \
129# define SAFE_DEALLOCATE_A(x) \
130 if(allocated(x)) then; \
138#define SAFE_TOL(x, tol) sign(max(abs(x),tol),x)
141! the TOSTRING macro converts a macro into a
string
142!
do not use the STRINGIFY macro
143#define STRINGIFY(x) #x
144#define TOSTRING(x) STRINGIFY(x)
147! Whenever a procedure is
not called too many times, one should
start it
148! and finish it with the PUSH_SUB and POP_SUB
macros, which are these
149! pieces of
code that call the push_sub and pop_sub routines defined
150!
in the messages_m module.
151#define PUSH_SUB(routine) \
155#define POP_SUB(routine) \
156 if(debug%trace .or. debug%instrument) then; if(not_in_openmp()) then; \
157 call debug_pop_sub(__FILE__+"."+TOSTRING(routine)); \
160! push_pop_mismatch: begin ignore
161#define PUSH_SUB_WITH_PROFILE(routine) \
163 call profiling_in(TOSTRING(routine));
164#define POP_SUB_WITH_PROFILE(routine) \
165 call profiling_out(TOSTRING(routine)); \
167! push_pop_mismatch: end ignore
ssize_t ssize_t write(int __fd, const void *__buf, size_t __n) __attribute__((__access__(__read_only__
if write to the Free Software Franklin Fifth USA !The assertions are ignored if the code is compiled in not debug when !prints out the assertion the and the line The subroutine !assert_die is in the global_m module !In octopus
if write to the Free Software Franklin Fifth USA !The assertions are ignored if the code is compiled in not debug when fails
if write to the Free Software Franklin Street
A A G Bertsch !This program is free software
!in the one should use SAFE_DEALLOCATE_P for pointers and SAFE_DEALLOCATE_A !for arrays !A special version of the SAFE_ALLOCATE macro named SAFE_ALLOCATE_TYPE is also !provided to allocate a polymorphic variable This is necessary because of the !special Fortran syntax type::var !Some versions of GCC have a bug in the one should start it !and finish it with the PUSH_SUB and POP_SUB macros
if write to the Free Software Franklin Fifth Boston
you can redistribute it and or modify !it under the terms of the GNU General Public License as published by !the Free Software Foundation
without even the implied warranty of !MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the !GNU General Public License for more details !You should have received a copy of the GNU General Public License !along with this program
if write to the Free Software Inc
if write to the Free Software Franklin Fifth USA !The assertions are ignored if the code is compiled in not debug when !prints out the assertion string
!in the one should use SAFE_DEALLOCATE_P for pointers and SAFE_DEALLOCATE_A !for arrays !A special version of the SAFE_ALLOCATE macro named SAFE_ALLOCATE_TYPE is also !provided to allocate a polymorphic variable This is necessary because of the !special Fortran syntax type::var !Some versions of GCC have a bug in the sizeof() function such that the compiler crashes with a ICE ! when passing a polymorphic variable to the function and explicit array bounds are given. ! The workaround is not to pass the bounds to sizeof. Otherwise we could just use SAFE_ALLOCATE_TYPE. ! the TOSTRING macro converts a macro into a string ! do not use the STRINGIFY macro ! Whenever a procedure is not called too many times
if write to the Free Software Franklin Fifth USA !The assertions are ignored if the code is compiled in not debug when !prints out the assertion the and the line The subroutine !assert_die is in the global_m module !In one should normally use the SAFE_(DE) ALLOCATE macros below
if write to the Free Software Franklin Fifth MA
either or(at your option) !! any later version. !! !! This program is distributed in the hope that it will be useful
if write to the Free Software Franklin Fifth USA !The assertions are ignored if the code is compiled in not debug when !prints out the assertion the file
if write to the Free Software Franklin Fifth USA !The assertions are ignored if the code is compiled in not debug mode(NDEBUG ! is defined). Otherwise it is merely a logical assertion that
if write to the Free Software Franklin Fifth Floor
either !but WITHOUT ANY WARRANTY
subroutine assert_die(s, f, l)
This subroutine is called by the assert macro, it is not in a module so it can be called from any fil...
type(debug_t), save, public debug
subroutine, public debug_push_sub(sub_name)
Push a routine to the debug trace.
logical pure function, public not_in_openmp()
character(len=100), public global_alloc_errmsg
integer, public global_alloc_err
logical pure function, public even(n)
Returns if n is even.
subroutine, public alloc_error(msg, stmt, file, line)
type(profile_vars_t), target, save, public prof_vars
subroutine, public profiling_memory_allocate(var, file, line, size_)
subroutine start()
start the timer (save starting time)