1 // ---------------------------------------------------------------------
4 // Copyright (C) 2004 - 2013 by the deal.II authors
6 // This file is part of the deal.II library.
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
15 // ---------------------------------------------------------------------
19 // assignment of ghost vectors
22 #include <deal.II/lac/generic_linear_algebra.h>
23 #include <deal.II/base/index_set.h>
34 unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD);
35 unsigned int numproc = Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD);
38 deallog << "numproc=" << numproc << std::endl;
40 // each processor owns 2 indices and all
41 // are ghosting Element 1 (the second)
43 IndexSet local_active(numproc*2);
44 local_active.add_range(myid*2,myid*2+2);
45 IndexSet local_relevant(numproc*2);
46 local_relevant.add_range(1,2);
48 typename LA::MPI::Vector vb(local_active, MPI_COMM_WORLD);
49 typename LA::MPI::Vector v(local_active, local_relevant, MPI_COMM_WORLD);
50 typename LA::MPI::Vector v2(local_active, local_relevant, MPI_COMM_WORLD);
57 vb(myid*2+1)=myid*2.0+1.0;
59 vb.compress(VectorOperation::insert);
63 Assert(vb.size() == numproc*2, ExcInternalError());
64 Assert(v.size() == numproc*2, ExcInternalError());
66 Assert(!vb.has_ghost_elements(), ExcInternalError());
67 Assert(v.has_ghost_elements(), ExcInternalError());
70 if (Utilities::MPI::this_mpi_process (MPI_COMM_WORLD) == 0)
72 deallog << myid*2 << ":" << v(myid*2) << std::endl;
73 deallog << myid*2+1 << ":" << v(myid*2+1) << std::endl;
76 //assignment from ghosted to ghosted
78 Assert(v2(1) == 2.0, ExcInternalError());
79 Assert(v2(myid*2) == myid*4.0, ExcInternalError());
80 Assert(v2(myid*2+1) == myid*4.0+2.0, ExcInternalError());
84 Assert(v(myid*2) == myid*4.0, ExcInternalError());
85 Assert(v(myid*2+1) == myid*4.0+2.0, ExcInternalError());
89 if (Utilities::MPI::this_mpi_process (MPI_COMM_WORLD) == 0)
90 deallog << "ghost: " << v(1) << std::endl;
91 Assert(v(1) == 2.0, ExcInternalError());
95 deallog << "OK" << std::endl;
100 int main (int argc, char **argv)
102 Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv);
103 unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD);
105 deallog.push(Utilities::int_to_string(myid));
109 std::ofstream logfile(output_file_for_mpi("vec_02").c_str());
110 deallog.attach(logfile);
111 deallog << std::setprecision(4);
112 deallog.depth_console(0);
113 deallog.threshold_double(1.e-10);
116 deallog.push("PETSc");
119 deallog.push("Trilinos");
127 deallog.push("PETSc");
130 deallog.push("Trilinos");
In the beginning the Universe was created. This has made a lot of
people very angry and has been widely regarded as a bad move.
Douglas Adams