Skip to content

Commit

Permalink
Add a test.
Browse files Browse the repository at this point in the history
  • Loading branch information
drwells committed Sep 5, 2023
1 parent 33b3f6b commit 89aed36
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
63 changes: 63 additions & 0 deletions tests/petsc/serialize_vector_01.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// ---------------------------------------------------------------------
//
// Copyright (C) 2023 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, 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 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE.md at
// the top level directory of deal.II.
//
// ---------------------------------------------------------------------

// Check that we can correctly serialize a vector via boost.

#include <deal.II/base/index_set.h>
#include <deal.II/base/mpi.h>

#include <deal.II/lac/petsc_vector.h>

#include "../tests.h"


int
main(int argc, char **argv)
{
Utilities::MPI::MPI_InitFinalize mpi_context(argc, argv, 1);
MPILogInitAll mpi_log;

const auto rank = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
const auto n_mpi_processes = Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD);

constexpr types::global_dof_index dofs_per_process = 5;
IndexSet owned_indices(dofs_per_process * n_mpi_processes);
owned_indices.add_range(dofs_per_process * rank,
dofs_per_process * (rank + 1));
owned_indices.compress();

owned_indices.print(deallog);

PETScWrappers::MPI::Vector petsc_vector(owned_indices, MPI_COMM_WORLD);
for (const auto dof : owned_indices)
petsc_vector(dof) = double(dof);

petsc_vector.compress(VectorOperation::insert);

std::stringstream stream;
boost::archive::binary_oarchive out_archive(stream);
out_archive << petsc_vector;

PETScWrappers::MPI::Vector petsc_copy(owned_indices, MPI_COMM_WORLD);

boost::archive::binary_iarchive in_archive(stream);
in_archive >> petsc_copy;

petsc_copy.print(deallog.get_file_stream());

AssertThrow(petsc_copy == petsc_vector, ExcInternalError());

deallog << "OK" << std::endl;
}
9 changes: 9 additions & 0 deletions tests/petsc/serialize_vector_01.mpirun=2.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

DEAL:0::{[0,4]}
[Proc0 0-4] 0.000e+00 1.000e+00 2.000e+00 3.000e+00 4.000e+00
DEAL:0::OK

DEAL:1::{[5,9]}
[Proc1 5-9] 5.000e+00 6.000e+00 7.000e+00 8.000e+00 9.000e+00
DEAL:1::OK

0 comments on commit 89aed36

Please sign in to comment.