Skip to content

Commit

Permalink
changed set to unordered_set
Browse files Browse the repository at this point in the history
  • Loading branch information
ttadano committed Dec 27, 2017
1 parent 63dfc90 commit 014813a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 21 deletions.
40 changes: 19 additions & 21 deletions alm/constraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "error.h"
#include <boost/bimap.hpp>
#include "mathfunctions.h"
#include <unordered_set>

#ifdef _USE_EIGEN
#include <Eigen/Dense>
Expand Down Expand Up @@ -609,7 +610,7 @@ void Constraint::get_symmetry_constraint(const int order, const std::set<IntList
int nsym_in_use;
double *arr_constraint;
bool has_constraint_from_symm = false;
std::set<FcProperty> list_found;
std::unordered_set<FcProperty> list_found;
std::vector<std::vector<double>> const_mat;
int **map_sym;
double ***rotation;
Expand Down Expand Up @@ -698,7 +699,7 @@ void Constraint::get_symmetry_constraint(const int order, const std::set<IntList
int *xyz_index;
double c_tmp;

std::set<FcProperty>::iterator iter_found;
std::unordered_set<FcProperty>::iterator iter_found;
std::vector<double> const_now_omp;
std::vector<std::vector<double>> const_omp;

Expand Down Expand Up @@ -816,8 +817,8 @@ void Constraint::translational_invariance()
double *arr_constraint;

std::vector<int> intlist, data;
std::set<FcProperty> list_found;
std::set<FcProperty>::iterator iter_found;
std::unordered_set<FcProperty> list_found;
std::unordered_set<FcProperty>::iterator iter_found;
std::vector<std::vector<int>> data_vec;
std::vector<FcProperty> list_vec;
std::vector<FcProperty>::iterator iter_vec;
Expand Down Expand Up @@ -1016,13 +1017,13 @@ void Constraint::translational_invariance()
const_omp.end());

// Merge vectors
#pragma omp critical
#pragma omp critical
{
for (auto it = const_omp.begin(); it != const_omp.end(); ++it) {
const_mat.push_back(*it);
}
}
const_omp.clear();
const_omp.clear();

}// close idata (openmp main loop)

Expand All @@ -1047,11 +1048,10 @@ void Constraint::translational_invariance()

// Copy to constraint class
const_translation[order].clear();
for (std::vector<std::vector<int>>::reverse_iterator it = const_mat.rbegin();
it != const_mat.rend(); ++it) {
for (auto it = const_mat.rbegin(); it != const_mat.rend(); ++it) {
for (i = 0; i < (*it).size(); ++i) {
arr_constraint[i] = static_cast<double>((*it)[i]);
}
}
const_translation[order].push_back(ConstraintClass(nparams,
arr_constraint));
}
Expand Down Expand Up @@ -1104,9 +1104,9 @@ void Constraint::rotational_invariance()

std::vector<int> interaction_list, interaction_list_old, interaction_list_now;

std::set<FcProperty> list_found;
std::set<FcProperty> list_found_last;
std::set<FcProperty>::iterator iter_found;
std::unordered_set<FcProperty> list_found;
std::unordered_set<FcProperty> list_found_last;
std::unordered_set<FcProperty>::iterator iter_found;

CombinationWithRepetition<int> g;

Expand Down Expand Up @@ -1142,16 +1142,15 @@ void Constraint::rotational_invariance()
memory->allocate(interaction_tmp, order + 2);

if (order > 0) {
list_found_last = list_found;
list_found_last = list_found;
nxyz = static_cast<int>(pow(static_cast<double>(3), order));
memory->allocate(xyzcomponent, nxyz, order);
fcs->get_xyzcomponent(order, xyzcomponent);
}

list_found.clear();

for (std::vector<FcProperty>::iterator p = fcs->fc_table[order].begin();
p != fcs->fc_table[order].end(); ++p) {
for (auto p = fcs->fc_table[order].begin(); p != fcs->fc_table[order].end(); ++p) {
for (i = 0; i < order + 2; ++i) {
ind[i] = (*p).elems[i];
}
Expand Down Expand Up @@ -1225,8 +1224,7 @@ void Constraint::rotational_invariance()


if (iter_found != list_found.end()) {
arr_constraint[(*iter_found).mother]
+= (*iter_found).sign * vec_for_rot[nu];
arr_constraint[(*iter_found).mother] += (*iter_found).sign * vec_for_rot[nu];
}

// Exchange mu <--> nu and repeat again.
Expand Down Expand Up @@ -1728,7 +1726,7 @@ void Constraint::rref(int nrows,
if (std::abs(mat[pivot][icol]) > tolerance) ++nrank;

if (pivot != irow) {
//#pragma omp parallel for private(tmp)
//#pragma omp parallel for private(tmp)
for (jcol = icol; jcol < ncols; ++jcol) {
tmp = mat[pivot][jcol];
mat[pivot][jcol] = mat[irow][jcol];
Expand All @@ -1738,7 +1736,7 @@ void Constraint::rref(int nrows,

tmp = mat[irow][icol];
tmp = 1.0 / tmp;
//#pragma omp parallel for
//#pragma omp parallel for
for (jcol = icol; jcol < ncols; ++jcol) {
mat[irow][jcol] *= tmp;
}
Expand All @@ -1747,7 +1745,7 @@ void Constraint::rref(int nrows,
if (jrow == irow) continue;

tmp = mat[jrow][icol];
//#pragma omp parallel for
//#pragma omp parallel for
for (jcol = icol; jcol < ncols; ++jcol) {
mat[jrow][jcol] -= tmp * mat[irow][jcol];
}
Expand Down Expand Up @@ -1891,7 +1889,7 @@ void Constraint::rref_nofraction(std::vector<std::vector<int>> &mat)
#ifdef _USE_EIGEN
void Constraint::get_column_space(std::vector<std::vector<int>> &mat)
{
// Return the column space of matrix mat.
// Return the column space of matrix mat.

using namespace Eigen;

Expand Down
29 changes: 29 additions & 0 deletions alm/fcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ namespace ALM_NS
return std::lexicographical_compare(elems.begin(), elems.end(),
a.elems.begin(), a.elems.end());
}

bool operator==(const FcProperty &a) const
{
int n = elems.size();
int n_ = a.elems.size();
if (n != n_) return false;
for (int i = 0; i < n; ++i) {
if (elems[i] != a.elems[i]) return false;
}
return true;
}
};

class ForceConstantTable
Expand Down Expand Up @@ -98,3 +109,21 @@ namespace ALM_NS
bool is_ascending(const int, const int *);
};
}


namespace std
{
template <>
struct hash<ALM_NS::FcProperty>
{
std::size_t operator () (ALM_NS::FcProperty const &obj) const
{
hash<int> hasher;
size_t seed = 0;
for (auto i : obj.elems) {
seed ^= hasher(i) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
return seed;
}
};
}

0 comments on commit 014813a

Please sign in to comment.