Commit 781c2c65 authored by Thomas Purcell's avatar Thomas Purcell
Browse files

initial omp implimentation for feature generation

it is slower for some reason I need to debug it
parent 5a5fbd6a
#include <feature_creation/feature_space/FeatureSpace.hpp>
#include <iomanip>
BOOST_CLASS_EXPORT_GUID(FeatureNode, "FeatureNode")
BOOST_CLASS_EXPORT_GUID(AddNode, "AddNode")
......@@ -180,10 +181,24 @@ void FeatureSpace::generate_feature_space(std::vector<double>& prop)
int feat_ind = _phi.size();
std::array<int, 2> start_end = _mpi_comm->get_start_end_from_list(_phi.size() - _start_gen.back(), _start_gen.back());
for(auto feat_1 = _phi.begin() + start_end[0]; feat_1 < _phi.begin() + start_end[1]; ++feat_1)
generate_new_feats(feat_1, next_phi, feat_ind, l_bound, u_bound);
_start_gen.push_back(_phi.size());
node_value_arrs::clear_temp_reg();
#pragma omp parallel firstprivate(feat_ind) default(shared)
{
std::vector<node_ptr> next_phi_private;
#pragma omp for schedule(auto)
for(auto feat_1 = _phi.begin() + start_end[0]; feat_1 < _phi.begin() + start_end[1]; ++feat_1)
generate_new_feats(feat_1, next_phi_private, feat_ind, l_bound, u_bound);
#pragma omp critical
{
next_phi.insert(next_phi.end(), next_phi_private.begin(), next_phi_private.end());
std::cout << omp_get_thread_num() << '\t' << next_phi_private.size() << std::endl;
}
}
_start_gen.push_back(_phi.size());
std::cout << omp_get_thread_num() << '\t' << _phi.size() << '\t' << next_phi.size() << std::endl;
node_value_arrs::clear_temp_reg();
if((nn < _max_phi) || (nn <= _n_rung_store) || (_mpi_comm->size() == 1))
{
......@@ -225,6 +240,7 @@ void FeatureSpace::generate_feature_space(std::vector<double>& prop)
throw std::logic_error("It appears that no new features were created during this rung, stopping here because there is likely something wrong with selected inputs.");
node_value_arrs::clear_temp_reg();
std::cout << _phi.size() << std::endl;
if(nn < _max_phi)
{
// Remove identical features
......@@ -240,10 +256,31 @@ void FeatureSpace::generate_feature_space(std::vector<double>& prop)
_mpi_comm->barrier();
for(int sc = 0; sc < _scores.size() - 1; ++sc)
if(_scores[inds[sc + 1]] - _scores[inds[sc]] < 1e-10)
if(std::abs(util_funcs::r(_phi[_start_gen.back() + inds[sc]]->value_ptr(), _phi[_start_gen.back() + inds[sc]]->value_ptr(), _n_samp) - std::abs(util_funcs::r(_phi[_start_gen.back() + inds[sc]]->value_ptr(), _phi[_start_gen.back() + inds[sc + 1]]->value_ptr(), _n_samp))) < 1e-13)
{
if(_scores[inds[sc]] > -1e-10)
{
for(int sc2 = sc + 1; sc2 < _scores.size(); ++sc2)
{
if(std::abs(util_funcs::r(_phi[_start_gen.back() + inds[sc]]->value_ptr(0), _phi[_start_gen.back() + inds[sc]]->value_ptr(1), _n_samp) - std::abs(util_funcs::r(_phi[_start_gen.back() + inds[sc]]->value_ptr(0), _phi[_start_gen.back() + inds[sc2]]->value_ptr(1), _n_samp))) < 1e-13)
{
// std::cout << _phi[_start_gen.back() + inds[sc]]->value_ptr(0) << '\t' << _phi[_start_gen.back() + inds[sc2]]->value_ptr(1) << '\t' << inds[sc] << '\t' << inds[sc2] << '\t' << std::setw(30) << _phi[_start_gen.back() + inds[sc2]]->expr() << '\t' << std::setw(30) << _phi[_start_gen.back() + inds[sc]]->expr() << '\t' << std::abs(util_funcs::r2(_phi[_start_gen.back() + inds[sc]]->value_ptr(), _phi[_start_gen.back() + inds[sc2]]->value_ptr(), _n_samp)) << std::endl;
del_inds.push_back(-1 * (inds[sc] + _start_gen.back()));
break;
}
}
}
else if(_scores[inds[sc + 1]] - _scores[inds[sc]] < 1e-10)
{
// std::cout << sc << '\t' << std::setw(30) << _phi[_start_gen.back() + inds[sc + 1]]->expr() << '\t' << std::setw(30) << _phi[_start_gen.back() + inds[sc]]->expr() << '\t' << _scores[inds[sc + 1]] << '\t' << _scores[inds[sc]] << std::endl;
if(std::abs(util_funcs::r(_phi[_start_gen.back() + inds[sc]]->value_ptr(0), _phi[_start_gen.back() + inds[sc]]->value_ptr(1), _n_samp) - std::abs(util_funcs::r(_phi[_start_gen.back() + inds[sc]]->value_ptr(0), _phi[_start_gen.back() + inds[sc + 1]]->value_ptr(1), _n_samp))) < 1e-13)
{
del_inds.push_back(-1 * (inds[sc] + _start_gen.back()));
}
}
}
inds = util_funcs::argsort(del_inds);
std::cout << del_inds.size() << std::endl;
for(int ii = 0; ii < inds.size(); ++ii)
_phi.erase(_phi.begin() - del_inds[inds[ii]]);
......@@ -252,6 +289,7 @@ void FeatureSpace::generate_feature_space(std::vector<double>& prop)
for(int ff = _start_gen.back(); ff < _phi.size(); ++ff)
_phi[ff]->reindex(ff);
}
std::cout << _phi.size() << std::endl;
if(nn <= _n_rung_store)
{
bool use_temp = (nn != _max_phi) || (_max_phi > _n_rung_store);
......
......@@ -67,22 +67,22 @@ void node_value_arrs::resize_values_arr(int n_dims, int n_feat, bool use_temp)
}
}
double* node_value_arrs::get_value_ptr(int arr_ind, int feat_ind, int offset, int thread)
double* node_value_arrs::get_value_ptr(int arr_ind, int feat_ind, int offset)
{
if(arr_ind < N_STORE_FEATURES)
return access_value_arr(arr_ind);
temp_storage_reg(arr_ind, offset) = feat_ind;
return access_temp_storage((arr_ind % N_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES) + thread * N_STORE_FEATURES * 3;
return access_temp_storage((arr_ind % N_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES + omp_get_thread_num() * N_STORE_FEATURES * 3);
}
double* node_value_arrs::get_test_value_ptr(int arr_ind, int feat_ind, int offset, int thread)
double* node_value_arrs::get_test_value_ptr(int arr_ind, int feat_ind, int offset)
{
if(arr_ind < N_STORE_FEATURES)
return access_test_value_arr(arr_ind);
temp_storage_test_reg(arr_ind, offset) = feat_ind;
return access_temp_storage_test((arr_ind % N_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES) + thread * N_STORE_FEATURES * 3;
return access_temp_storage_test((arr_ind % N_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES + omp_get_thread_num() * N_STORE_FEATURES * 3);
}
void node_value_arrs::initialize_d_matrix_arr()
......
......@@ -77,7 +77,7 @@ namespace node_value_arrs
*
* @return The register element for a given feature index and offset
*/
inline int& temp_storage_reg(int ind, int offset = 0, int thread = omp_get_thread_num()){return TEMP_STORAGE_REG[(ind % N_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES + thread * N_STORE_FEATURES * 3];}
inline int& temp_storage_reg(int ind, int offset = 0){return TEMP_STORAGE_REG[(ind % N_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES + omp_get_thread_num() * N_STORE_FEATURES * 3];}
/**
* @brief Get a reference slot/feature register of the test data
......@@ -87,7 +87,7 @@ namespace node_value_arrs
*
* @return The register element for a given feature index and offset
*/
inline int& temp_storage_test_reg(int ind, int offset = 0, int thread = omp_get_thread_num()){return TEMP_STORAGE_TEST_REG[(ind % N_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES + thread * N_STORE_FEATURES * 3];}
inline int& temp_storage_test_reg(int ind, int offset = 0){return TEMP_STORAGE_TEST_REG[(ind % N_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES + omp_get_thread_num() * N_STORE_FEATURES * 3];}
/**
* @brief Access element of the permanent training data storage array
......@@ -134,7 +134,7 @@ namespace node_value_arrs
*
* @return The value pointer
*/
double* get_value_ptr(int arr_ind, int feat_ind, int offset = 0, int thread = omp_get_thread_num());
double* get_value_ptr(int arr_ind, int feat_ind, int offset = 0);
/**
* @brief Get a Node's test_value_ptr
......@@ -145,7 +145,7 @@ namespace node_value_arrs
*
* @return The value pointer
*/
double* get_test_value_ptr(int arr_ind, int feat_ind, int offset = 0, int thread = omp_get_thread_num());
double* get_test_value_ptr(int arr_ind, int feat_ind, int offset = 0);
/**
* @brief Get the pointer to a particular selected Node from sis
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment