Skip to content

Commit

Permalink
Added -Wall (gcc) & /W4 (MVC) flags and fixed warnings for gcc.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cobra8 committed Oct 24, 2023
1 parent b399c5c commit 5567e82
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 45 deletions.
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ set(SRC_FILES

add_executable(dphpc ${SRC_FILES})

if(MSVC)
target_compile_options(dphpc PRIVATE /W4)
else()
target_compile_options(dphpc PRIVATE -Wall)
endif()

if(MSVC)
source_group(TREE ${CMAKE_SOURCE_DIR} FILES ${SRC_FILES})
endif()
Expand Down
13 changes: 6 additions & 7 deletions src/competitors/cpu/cpu_basic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ namespace Competitors {
{}

virtual inline void run_csr(Dense<T> &A, Dense<T> &B, CSR<T> &S, CSR<T> &P) {
const unsigned int K = B.getCols();
const unsigned int M = S.getRows();
const int K = B.getCols();
const int M = S.getRows();

for (int i = 0; i < M; i++) {
for (int j = S.getRowPositions()[i]; j < S.getRowPositions()[i+1]; j++) {
Expand All @@ -28,7 +28,7 @@ namespace Competitors {
}
}

for (int i = 0; i < S.getRowPositions().size() - 1; i++) {
for (uint32_t i = 0; i < S.getRowPositions().size() - 1; i++) {
for (int j = S.getRowPositions()[i]; j < S.getRowPositions()[i+1]; j++) {
(*P.getValue(j)) *= S.getValues()[j];
}
Expand All @@ -37,17 +37,16 @@ namespace Competitors {
}

virtual inline void run_coo(Dense<T> &A, Dense<T> &B, COO<T> &S, COO<T> &P) {
const unsigned int K = B.getCols();
const unsigned int M = S.getRows();
const int K = B.getCols();

for (int i = 0; i < S.getValues().size(); i++) {
for (uint32_t i = 0; i < S.getValues().size(); i++) {
*P.getValue(i) = static_cast<T>(0);
for (int k = 0; k < K; k++) {
(*P.getValue(i)) += A.getValue(S.getRowPositions()[i], k) * B.getValue(S.getColPositions()[i], k);
}
}

for (int i = 0; i < S.getValues().size(); i++) {
for (uint32_t i = 0; i < S.getValues().size(); i++) {
(*P.getValue(i)) *= S.getValues()[i];
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static void print_config(Config config) {
DEBUG_OUT("----------------------------------------" << std::endl);
}

static void usage(const char *argv0) {
static void usage() {
std::cout << "----------------------------------------" << std::endl;
std::cout << "Options:" << std::endl;
std::cout << " -d, --data_folder <folder> (folder to read datasets from)" << std::endl;
Expand All @@ -97,7 +97,6 @@ int main(int argc, char* argv[]) {
};

#ifndef _WIN32
int K = 32;
static struct option long_options[] = {
{ .name = "data_folder", .has_arg = 1, .val = 'd' },
{ .name = "K", .has_arg = 1, .val = 'k' },
Expand All @@ -111,7 +110,7 @@ int main(int argc, char* argv[]) {
} else if (c == 'k') {
config.K = std::stoi(optarg);
} else {
usage(argv[0]);
usage();
return 1;
}
}
Expand Down
29 changes: 12 additions & 17 deletions src/matrices/COO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,14 @@ template<class T>
class COO {
public:

COO() {
this->rows = 0;
this->cols = 0;

this->rowPositions = std::vector<int>(0);
this->colPositions = std::vector<int>(0);
this->values = std::vector<T>(0);
}
COO()
: rows(0), cols(0), rowPositions(std::vector<int>(0)), colPositions(std::vector<int>(0)), values(std::vector<T>(0))
{ }

COO(int rows, int cols, std::vector<Triplet<T>> values) {
COO(int rows, int cols, std::vector<Triplet<T>> values)
: rows(rows), cols(cols) {
assert(values.size() > 0);

this->rows = rows;
this->cols = cols;

this->rowPositions = std::vector<int>(0);
this->colPositions = std::vector<int>(0);
this->values = std::vector<T>(0);
Expand All @@ -50,7 +43,9 @@ class COO {
}
}

COO(const COO &other) : rows(other.rows), cols(other.cols), values(other.values), colPositions(other.colPositions), rowPositions(other.rowPositions) {}
COO(const COO &other)
: rows(other.rows), cols(other.cols), rowPositions(other.rowPositions), colPositions(other.colPositions), values(other.values)
{}

COO(CSR<T> &csr) {
this->rows = csr.getRows();
Expand Down Expand Up @@ -107,7 +102,7 @@ class COO {
return false;
}

for(int i = 0; i < lhs.values.size();i++) {
for(uint32_t i = 0; i < lhs.values.size();i++) {
valMatch &= abs(rhs.values[i] - lhs.values[i]) <= 1e-6;
}
}
Expand Down Expand Up @@ -156,11 +151,11 @@ class COO {
}

private:
std::vector<int> colPositions;
std::vector<int> rowPositions;
std::vector<T> values;
int rows;
int cols;
std::vector<int> rowPositions;
std::vector<int> colPositions;
std::vector<T> values;
};


Expand Down
31 changes: 13 additions & 18 deletions src/matrices/CSR.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,26 @@ template<class T>
class CSR {
public:

CSR() {
this->rows = 0;
this->cols = 0;

this->rowPositions = std::vector<int>(0);
this->colPositions = std::vector<int>(0);
this->values = std::vector<T>(0);
}

CSR(int rows, int cols, std::vector<Triplet<T>> triplets) {
this->rows = rows;
this->cols = cols;
CSR()
: rows(0), cols(0), rowPositions(std::vector<int>(0)), colPositions(std::vector<int>(0)), values(std::vector<T>(0))
{}

CSR(int rows, int cols, std::vector<Triplet<T>> triplets)
: rows(rows), cols(cols) {
init_csr(triplets);
}

CSR(const CSR &other) : rows(other.rows), cols(other.cols), values(other.values), colPositions(other.colPositions), rowPositions(other.rowPositions) {}
CSR(const CSR &other)
: rows(other.rows), cols(other.cols), rowPositions(other.rowPositions), colPositions(other.colPositions), values(other.values)
{}

CSR(COO<T> &coo) {
this->rows = coo.getRows();
this->cols = coo.getCols();

std::vector<Triplet<T>> triplets(coo.getValues().size());

for (int i = 0; i < coo.getValues().size(); i++) {
for (uint32_t i = 0; i < coo.getValues().size(); i++) {
triplets[i].row = coo.getRowPositions()[i];
triplets[i].col = coo.getColPositions()[i];
triplets[i].value = coo.getValues()[i];
Expand Down Expand Up @@ -86,7 +81,7 @@ class CSR {
return false;
}

for(int i = 0; i < lhs.values.size();i++) {
for(uint32_t i = 0; i < lhs.values.size();i++) {
valMatch &= abs(rhs.values[i] - lhs.values[i]) <= 1e-6;
}
}
Expand Down Expand Up @@ -135,11 +130,11 @@ class CSR {
}

private:
std::vector<int> colPositions;
std::vector<int> rowPositions;
std::vector<T> values;
int rows;
int cols;
std::vector<int> rowPositions;
std::vector<int> colPositions;
std::vector<T> values;

void init_csr(std::vector<Triplet<T>> triplets) {
assert(triplets.size() > 0);
Expand Down

0 comments on commit 5567e82

Please sign in to comment.