Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F78835583
test_sparse_matrix_product.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Aug 23, 06:10
Size
3 KB
Mime Type
text/x-c
Expires
Sun, Aug 25, 06:10 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
20106124
Attached To
rAKA akantu
test_sparse_matrix_product.cc
View Options
/**
* Copyright (©) 2011-2023 EPFL (Ecole Polytechnique Fédérale de Lausanne)
* Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
*
* This file is part of Akantu
*
* Akantu is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* Akantu is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Akantu. If not, see <http://www.gnu.org/licenses/>.
*/
/* -------------------------------------------------------------------------- */
#include <iostream>
/* -------------------------------------------------------------------------- */
#include "aka_common.hh"
#include "dof_synchronizer.hh"
#include "element_synchronizer.hh"
#include "mesh.hh"
#include "mesh_partition_scotch.hh"
#include "sparse_matrix_aij.hh"
/* -------------------------------------------------------------------------- */
using namespace akantu;
/* -------------------------------------------------------------------------- */
int main(int argc, char * argv[]) {
initialize(argc, argv);
const Int spatial_dimension = 2;
const Int nb_dof = 2;
const auto & comm = Communicator::getStaticCommunicator();
Int psize = comm.getNbProc();
Int prank = comm.whoAmI();
Mesh mesh(spatial_dimension);
mesh.read("bar.msh");
mesh.distribute();
Int nb_nodes = mesh.getNbNodes();
DOFManagerDefault dof_manager(mesh, "test_dof_manager");
Array<Real> test_synchronize(nb_nodes, nb_dof, "Test vector");
dof_manager.registerDOFs("test_synchronize", test_synchronize, _dst_nodal);
if (prank == 0)
std::cout << "Creating a SparseMatrix" << std::endl;
auto & A = dynamic_cast<SparseMatrixAIJ &>(
dof_manager.getNewMatrix("A", _symmetric));
Array<Real> dof_vector(nb_nodes, nb_dof, "vector");
if (prank == 0)
std::cout << "Filling the matrix" << std::endl;
for (Int i = 0; i < nb_nodes * nb_dof; ++i) {
if (dof_manager.isLocalOrMasterDOF(i))
A.add(i, i, 2.);
}
std::stringstream str;
str << "Matrix_" << prank << ".mtx";
A.saveMatrix(str.str());
for (Int n = 0; n < nb_nodes; ++n) {
for (Int d = 0; d < nb_dof; ++d) {
dof_vector(n, d) = 1.;
}
}
Array<Real> dof_vector_tmp(dof_vector);
if (prank == 0)
std::cout << "Computing x = A * x" << std::endl;
A.matVecMul(dof_vector, dof_vector_tmp);
dof_vector.copy(dof_vector_tmp);
auto & sync =
dynamic_cast<DOFManagerDefault &>(dof_manager).getSynchronizer();
if (prank == 0)
std::cout << "Gathering the results on proc 0" << std::endl;
if (psize > 1) {
if (prank == 0) {
Array<Real> gathered;
sync.gather(dof_vector, gathered);
debug::setDebugLevel(dblTest);
std::cout << gathered << std::endl;
debug::setDebugLevel(dblWarning);
} else {
sync.gather(dof_vector);
}
} else {
debug::setDebugLevel(dblTest);
std::cout << dof_vector << std::endl;
debug::setDebugLevel(dblWarning);
}
finalize();
return 0;
}
Event Timeline
Log In to Comment