Skip to content

Commit

Permalink
Remove unused instance and value caching from NetCDF mesh provider
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilMiller committed Sep 17, 2024
1 parent aab3cdc commit 9fd9510
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 44 deletions.
20 changes: 0 additions & 20 deletions include/forcing/NetCDFMeshPointsDataProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,6 @@ namespace data_access

using time_point_type = std::chrono::time_point<std::chrono::system_clock>;

/**
* @brief Factory method that creates or returns an existing provider for the provided path.
* @param input_path The path to a NetCDF file with lumped catchment forcing values.
* @param log_s An output log stream for messages from the underlying library. If a provider object for
* the given path already exists, this argument will be ignored.
*/
static std::shared_ptr<NetCDFMeshPointsDataProvider> get_shared_provider(std::string input_path, time_point_type sim_start, time_point_type sim_end);

/**
* @brief Cleanup the shared providers cache, ensuring that the files get closed.
*/
static void cleanup_shared_providers();

NetCDFMeshPointsDataProvider(std::string input_path,
time_point_type sim_start,
time_point_type sim_end);
Expand Down Expand Up @@ -133,9 +120,6 @@ namespace data_access
time_point_type sim_end_date_time_epoch;
std::chrono::seconds sim_to_data_time_offset; // Deliberately signed--sim should never start before data, yes?

static std::mutex shared_providers_mutex;
static std::map<std::string, std::shared_ptr<NetCDFMeshPointsDataProvider>> shared_providers;

std::vector<std::string> variable_names;
std::vector<time_point_type> time_vals;
std::chrono::seconds time_stride; // the amount of time between stored time values
Expand All @@ -144,10 +128,6 @@ namespace data_access

struct metadata_cache_entry;
std::map<std::string, metadata_cache_entry> ncvar_cache;

boost::compute::detail::lru_cache<std::string, std::shared_ptr<std::vector<double>>> value_cache;
size_t cache_slice_t_size = 1;
size_t cache_slice_c_size = 1;
};
}

Expand Down
25 changes: 1 addition & 24 deletions src/forcing/NetCDFMeshPointsDataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#include <chrono>
#include <netcdf>

std::mutex data_access::NetCDFMeshPointsDataProvider::shared_providers_mutex;
std::map<std::string, std::shared_ptr<data_access::NetCDFMeshPointsDataProvider>> data_access::NetCDFMeshPointsDataProvider::shared_providers;

namespace data_access {

// Out-of-line class definition after forward-declaration so that the
Expand All @@ -20,28 +17,8 @@ struct NetCDFMeshPointsDataProvider::metadata_cache_entry {
double offset;
};

std::shared_ptr<NetCDFMeshPointsDataProvider> NetCDFMeshPointsDataProvider::get_shared_provider(std::string input_path, time_point_type sim_start, time_point_type sim_end)
{
const std::lock_guard<std::mutex> lock(shared_providers_mutex);
std::shared_ptr<NetCDFMeshPointsDataProvider> p;
if(shared_providers.count(input_path) > 0){
p = shared_providers[input_path];
} else {
p = std::make_shared<data_access::NetCDFMeshPointsDataProvider>(input_path, sim_start, sim_end);
shared_providers[input_path] = p;
}
return p;
}

void NetCDFMeshPointsDataProvider::cleanup_shared_providers()
{
const std::lock_guard<std::mutex> lock(shared_providers_mutex);
// First lets try just emptying the map... if all goes well, everything will destruct properly on its own...
shared_providers.clear();
}

NetCDFMeshPointsDataProvider::NetCDFMeshPointsDataProvider(std::string input_path, time_point_type sim_start, time_point_type sim_end)
: value_cache(20),
:
sim_start_date_time_epoch(sim_start),
sim_end_date_time_epoch(sim_end)
{
Expand Down

0 comments on commit 9fd9510

Please sign in to comment.