-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #232 from bluescarni/pr/complex
Complex class
- Loading branch information
Showing
69 changed files
with
13,424 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2016-2020 Francesco Biscani ([email protected]) | ||
// | ||
// This file is part of the mp++ library. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla | ||
// Public License v. 2.0. If a copy of the MPL was not distributed | ||
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#include "track_malloc.hpp" | ||
|
||
#if defined(MPPP_HAVE_GLIBC) | ||
|
||
#include <atomic> | ||
#include <cstddef> | ||
#include <iostream> | ||
|
||
namespace mppp_bench | ||
{ | ||
|
||
namespace detail | ||
{ | ||
|
||
namespace | ||
{ | ||
|
||
// The tracking counter. This will be increased | ||
// each time the malloc() override below is | ||
// invoked. | ||
std::atomic<std::size_t> malloc_counter(0); | ||
|
||
} // namespace | ||
|
||
} // namespace detail | ||
|
||
} // namespace mppp_bench | ||
|
||
// NOTE: see here for an explanation: | ||
// https://stackoverflow.com/questions/17803456/an-alternative-for-the-deprecated-malloc-hook-functionality-of-glibc | ||
extern "C" void *__libc_malloc(std::size_t size); | ||
|
||
// NOTE: apparently it is not necessary to declare | ||
// this function as visible. | ||
extern "C" void *malloc(std::size_t size) | ||
{ | ||
++mppp_bench::detail::malloc_counter; | ||
return ::__libc_malloc(size); | ||
} | ||
|
||
namespace mppp_bench | ||
{ | ||
|
||
malloc_tracker::malloc_tracker(const char *s) : m_name(s), m_count(detail::malloc_counter.load()) {} | ||
|
||
malloc_tracker::~malloc_tracker() | ||
{ | ||
// NOTE: compute the total number of allocations | ||
// before outputting to stream, so that we avoid | ||
// counting possible allocations from stream operations. | ||
const auto tot_nalloc = detail::malloc_counter.load() - m_count; | ||
std::cout << "Tracker '" << m_name << "' observed " << tot_nalloc << " malloc() calls." << std::endl; | ||
} | ||
|
||
} // namespace mppp_bench | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2016-2020 Francesco Biscani ([email protected]) | ||
// | ||
// This file is part of the mp++ library. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla | ||
// Public License v. 2.0. If a copy of the MPL was not distributed | ||
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#ifndef MPPP_BENCHMARK_TRACK_MALLOC_HPP | ||
#define MPPP_BENCHMARK_TRACK_MALLOC_HPP | ||
|
||
// Machinery to check the presence of GLIBC. See: | ||
// https://sourceforge.net/p/predef/wiki/Libraries/ | ||
#include <climits> | ||
|
||
#if defined(__GNU_LIBRARY__) || defined(__GLIBC__) | ||
|
||
#define MPPP_HAVE_GLIBC | ||
|
||
#endif | ||
|
||
#if defined(MPPP_HAVE_GLIBC) | ||
|
||
#include <cstddef> | ||
#include <string> | ||
|
||
namespace mppp_bench | ||
{ | ||
|
||
struct __attribute__((visibility("default"))) malloc_tracker { | ||
explicit malloc_tracker(const char *); | ||
~malloc_tracker(); | ||
// NOTE: it is important than m_name | ||
// is inited befor m_count, so that | ||
// we don't end up counting allocations | ||
// from the string. | ||
std::string m_name; | ||
std::size_t m_count; | ||
}; | ||
|
||
} // namespace mppp_bench | ||
|
||
#else | ||
|
||
namespace mppp_bench | ||
{ | ||
|
||
struct malloc_tracker { | ||
explicit malloc_tracker(const char *) {} | ||
~malloc_tracker() {} | ||
}; | ||
|
||
} // namespace mppp_bench | ||
|
||
#endif | ||
|
||
#endif |
Oops, something went wrong.