Skip to content
Snippets Groups Projects
Commit be1c8947 authored by Thomas Purcell's avatar Thomas Purcell
Browse files

Create the MPI comparision/reduce operators

What will be used for a distributed sort
parent fdf9db26
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@
# Basic Flags #
###############
set(CMAKE_CXX_COMPILER g++ CACHE STRING "")
set(CMAKE_CXX_FLAGS "-O2" CACHE STRING "")
set(CMAKE_CXX_FLAGS "-O3 -march=native" CACHE STRING "")
#################
# Feature Flags #
......
......@@ -2,7 +2,7 @@
# Basic Flags #
###############
set(CMAKE_CXX_COMPILER g++ CACHE STRING "")
set(CMAKE_CXX_FLAGS "-O2" CACHE STRING "")
set(CMAKE_CXX_FLAGS "-O3 -march=native" CACHE STRING "")
#################
# Feature Flags #
......
......@@ -2,7 +2,7 @@
# Basic Flags #
###############
set(CMAKE_CXX_COMPILER icpc CACHE STRING "")
set(CMAKE_CXX_FLAGS "-O3" CACHE STRING "")
set(CMAKE_CXX_FLAGS "-O3 -xhost" CACHE STRING "")
#################
# Feature Flags #
......
......@@ -2,7 +2,7 @@
# Basic Flags #
###############
set(CMAKE_CXX_COMPILER icpc CACHE STRING "")
set(CMAKE_CXX_FLAGS "-O3" CACHE STRING "")
set(CMAKE_CXX_FLAGS "-O3 -xhost" CACHE STRING "")
#################
# Feature Flags #
......
#include<mpi_interface/MPI_ops.hpp>
void mpi_reduce_op::set_op(double cross_cor_max)
{
_cross_cor_max = cross_cor_max;
if(_cross_cor_max < 0.99999)
_is_valid = comp_feats::valid_feature_against_selected_feat_sc_list;
else
_is_valid = comp_feats::valid_feature_against_selected_max_corr_1_feat_sc_list;
}
\ No newline at end of file
/** @file mpi_interface/MPI_Ops.hpp
* @brief Define MPI reduce all operator to facilitate a distributed sorting algorithm
*
* This is based off of a project from Meisam Farzalipour Tabriz at the MPCDF (mpi_topk)
*
* @author Thomas A. R. Purcell (tpurcell)
* @bug No known bugs.
*/
#ifndef SISSO_MPI_OPS
#define SISSO_MPI_OPS
#include <boost/mpi.hpp>
#include <feature_creation/node/Node.hpp>
#include <utils/compare_features.hpp>
namespace mpi_reduce_op
{
std::function<bool(double*, int, double, node_sc_pair*, node_sc_pair*, double)> _is_valid; //!< Function used to calculate the scores for SIS without changing omp environment
double _cross_cor_max; //!< The maximum cross correlation between features
inline bool my_sorter(node_sc_pair node_1, node_sc_pair node_2){ return (std::get<1>(node_1) < std::get<1>(node_2)); }
template <int N>
void select_top_N(void* input_list, void* output_list, int* length, MPI_Datatype* datatype)
{
std::vector<node_sc_pair> merged_list;
const int top_items_number = N;
for(int ii=0; ii < *length; ++ii)
{
const int index_first = ii * top_items_number;
const int index_last = index_first + top_items_number;
merged_list.insert(merged_list.end(), static_cast<node_sc_pair*>(input_list)+index_first, static_cast<node_sc_pair*>(input_list)+index_last);
merged_list.insert(merged_list.end(), static_cast<node_sc_pair*>(output_list)+index_first, static_cast<node_sc_pair*>(output_list)+index_last);
std::sort(merged_list.begin(), merged_list.end(), my_sorter);
int ind = index_first;
int mi = 0;
while(ind != index_last)
{
const node_ptr cur_node = std::get<0>(merged_list[mi]);
if(_is_valid(cur_node->value_ptr(), cur_node->n_samp(), _cross_cor_max, static_cast<node_sc_pair*>(output_list) + index_first, static_cast<node_sc_pair*>(output_list) + ind, std::get<1>(merged_list[mi])))
{
static_cast<node_sc_pair*>(output_list)[ind] = merged_list[mi];
++ind;
}
++mi;
}
}
}
void set_op(double cross_cor_max);
}
#endif
\ No newline at end of file
......@@ -83,10 +83,10 @@ bool comp_feats::valid_feature_against_selected_max_corr_1_feat_sc_list(double*
for(auto feat_sc = start; feat_sc < end; ++feat_sc)
{
if(abs(cur_score - std::get<1>(feat_sc)) > 1e-5)
if(abs(cur_score - feat_sc->second) > 1e-5)
continue;
if((base_val - std::abs(util_funcs::r(std::get<0>(feat_sc)->value_ptr(1), val_ptr, n_samp))) < 1e-9)
if((base_val - std::abs(util_funcs::r(feat_sc->first->value_ptr(1), val_ptr, n_samp))) < 1e-9)
return false;
}
return true;
......@@ -98,7 +98,7 @@ bool comp_feats::valid_feature_against_selected_feat_sc_list(double* val_ptr, in
for(auto feat_sc = start; feat_sc < end; ++feat_sc)
{
if((base_val - std::abs(util_funcs::r(std::get<1>(feat_sc)->value_ptr(1), val_ptr, n_samp))) < (1.0 - cross_cor_max + 1e-10))
if((base_val - std::abs(util_funcs::r(feat_sc->first->value_ptr(1), val_ptr, n_samp))) < (1.0 - cross_cor_max + 1e-10))
return false;
}
return true;
......
......@@ -7,12 +7,12 @@
#ifndef UTILS_FEAT_COMP
#define UTILS_FEAT_COMP
#include <tuple>
#include <utility>
#include <feature_creation/node/Node.hpp>
#include <classification/utils.hpp>
typedef std::tuple<node_ptr, double> node_sc_pair;
typedef std::pair<node_ptr, double> node_sc_pair;
namespace comp_feats
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment