Task 5, 5* some fixes and cleanup

This commit is contained in:
Markus Schmidt 2025-12-09 23:33:08 +01:00
commit c8bf307391
154 changed files with 214851 additions and 93 deletions

View file

@ -8,6 +8,7 @@
#include <iostream>
#include <list>
#include <vector>
#include <omp.h>
using namespace std;
@ -168,33 +169,64 @@ void CRS_Matrix::Debug() const
void CRS_Matrix::CalculateLaplace(vector<double> &f)
{
double t_start = omp_get_wtime();
double t0 ,t1,t2;
assert(_mesh.NdofsElement() == 3); // only for triangular, linear elements
//cout << _nnz << " vs. " << _id[_nrows] << " " << _nrows<< endl;
assert(_nnz == _id[_nrows]);
for (int k = 0; k < _nrows; ++k)
#pragma omp parallel
{
_sk[k] = 0.0;
}
for (int k = 0; k < _nrows; ++k)
{
f[k] = 0.0;
}
#pragma omp for
for (int k = 0; k < _nrows; ++k)
{
_sk[k] = 0.0;
}
double ske[3][3], fe[3];
// Loop over all elements
auto const nelem = _mesh.Nelems();
auto const &ia = _mesh.GetConnectivity();
auto const &xc = _mesh.GetCoords();
#pragma omp barrier
#pragma omp single
t0 = omp_get_wtime();
#pragma omp for
for (int k = 0; k < _nrows; ++k)
{
f[k] = 0.0;
}
#pragma omp barrier
#pragma omp single
t1 = omp_get_wtime();
double ske[3][3], fe[3];
// Loop over all elements
auto const nelem = _mesh.Nelems();
auto const &ia = _mesh.GetConnectivity();
auto const &xc = _mesh.GetCoords();
#pragma omp barrier
#pragma omp single
t2 = omp_get_wtime();
#pragma omp for
for (int i = 0; i < nelem; ++i)
{
CalcElem(ia.data() + 3 * i, xc.data(), ske, fe);
AddElem_3(ia.data() + 3 * i, ske, fe, f);
}
//Debug();
for (int i = 0; i < nelem; ++i)
{
CalcElem(ia.data() + 3 * i, xc.data(), ske, fe);
AddElem_3(ia.data() + 3 * i, ske, fe, f);
}
//Debug();
double t3 = omp_get_wtime();
cout << "Zero matrix: " << (t0 - t_start) << " sec\n";
cout << "Zero RHS: " << (t1 - t0) << " sec\n";
cout << "Element loop: " << (t3 - t2) << " sec\n";
cout << "Total assembly:" << (t3 - t_start) << " sec\n";
return;
}
void CRS_Matrix::ApplyDirichletBC(std::vector<double> const &u, std::vector<double> &f)
@ -286,7 +318,8 @@ void CRS_Matrix::Defect(vector<double> &w,
{
assert( _nrows == static_cast<int>(w.size()) );
assert( w.size() == u.size() && u.size() == f.size() );
#pragma omp parallel for
for (int row = 0; row < _nrows; ++row)
{
double wi = f[row];
@ -340,8 +373,10 @@ void CRS_Matrix::AddElem_3(int const ial[3], double const ske[3][3], double cons
assert(ip >= 0);
}
#endif
#pragma omp atomic
_sk[ip] += ske[i][j];
}
#pragma omp atomic
f[ii] += fe[i];
}
}