This commit is contained in:
WickedJack99
2025-05-06 14:38:17 +02:00
parent 06b8e6cc7d
commit a83f565191
4 changed files with 50 additions and 18 deletions

View File

@@ -45,6 +45,7 @@
* -------------
*/
#include <benchmark/benchmark.h>
#include "matrix.h"
#include <omp.h>
#include <atomic>
@@ -168,24 +169,49 @@ void print_matrix(const Matrix &matrix)
}
}
int main()
{
Matrix first = Matrix(8, 8);
Matrix sec = Matrix(8, 8);
fill_matrix(first, 10);
void benchmarkComputeResult(benchmark::State& state) {
int iterations = state.range(0);
Matrix sec = Matrix(1000, 1000);
fill_matrix(sec, 10);
print_matrix(first);
print_matrix(sec);
for (auto _ : state) {
gauss_seidel(sec, iterations);
benchmark::DoNotOptimize(sec);
}
}
gauss_seidel_lin(first, 1000);
gauss_seidel(sec, 1000);
int main(int argc, char** argv) {
::benchmark::Initialize(&argc, argv);
check(first, sec);
for (int iterations = 0; iterations < 10000; iterations++) {
benchmark::RegisterBenchmark("idk", benchmarkComputeResult)
->Arg(iterations)
->Unit(benchmark::kMillisecond);
}
print_matrix(first);
print_matrix(sec);
::benchmark::RunSpecifiedBenchmarks();
return 0;
}
}
// int main()
// {
// Matrix first = Matrix(8, 8);
// Matrix sec = Matrix(8, 8);
// fill_matrix(first, 10);
// fill_matrix(sec, 10);
// print_matrix(first);
// print_matrix(sec);
// gauss_seidel_lin(first, 1000);
// gauss_seidel(sec, 1000);
// check(first, sec);
// print_matrix(first);
// print_matrix(sec);
// return 0;
// }

View File

@@ -13,6 +13,7 @@ void DBSCAN::run(const std::vector<Point>& points) {
const int n = dataset_.size();
int clusterIndex = 0;
#pragma omp parallel for
for (int i = 0; i < n; ++i) {
Point& point = dataset_[i];
if (point.clusterID < 0) {
@@ -56,7 +57,7 @@ std::set<int> DBSCAN::initializeNeighbors() {
Point& pointToCheckNeighborsFor = dataset_[i];
for (int j = 0; j < dataset_.size(); ++j) {
if (pointToCheckNeighborsFor.distance(dataset_[j]) <= epsilon_) {
pointToCheckNeighborsFor.neighbors.insert(j);
pointToCheckNeighborsFor.neighbors.insert(j);
}
}
}

View File

@@ -1,4 +1,4 @@
#include "dbscan.h"
#include "dbscan_serial.h"
#include <cmath>
#include <iostream>
@@ -11,6 +11,7 @@ void DBSCAN::run(const std::vector<Point>& points) {
const int n = dataset_.size();
int clusterIndex = 0;
for (int i = 0; i < n; ++i) {
Point& point = dataset_[i];
if (point.clusterID < 0) {
@@ -23,6 +24,10 @@ void DBSCAN::run(const std::vector<Point>& points) {
}
}
}
for (Point point : dataset_) {
std::cout << point << std::endl;
}
}
bool DBSCAN::expandCluster(Point& p, std::set<int>& neighbours, int clusterID) {

View File

@@ -6,11 +6,11 @@
# SOURCE_FILES: The source files of the algorithm, used for each build.
# You can add more source files here if needed.
SOURCE_FILES = dbscan.cpp point.cpp
SOURCE_FILES = dbscan_serial.cpp point.cpp
# Main rogram, used to cluster the data and save the result.
# PROGRAM_NAME: The name of the program that will be generated after compilation.
PROGRAM_NAME = dbscan
PROGRAM_NAME = dbscan_serial
RUN_MAIN = run.cpp
# Benchmark program: This program is used to benchmark the performance of the algorithm.