Hi all, I would like to extract a subvector of a distributed PetscVector using the create_subvector routine. My example programs looks as follows:
#include <iostream> #include <algorithm> #include <math.h> #include "libmesh/libmesh.h" #include "libmesh/mesh.h" #include "libmesh/mesh_generation.h" #include "libmesh/linear_implicit_system.h" #include "libmesh/equation_systems.h" #include "libmesh/numeric_vector.h" #include "libmesh/elem.h" #include "libmesh/dof_map.h" #include "libmesh/petsc_vector.h" using namespace libMesh; int main (int argc, char** argv) { LibMeshInit init (argc, argv); Mesh mesh(init.comm()); MeshTools::Generation::build_square (mesh,10,10,-1., 1.,-1., 1., QUAD4); mesh.print_info(); EquationSystems es(mesh); const std::string system_name = "Poisson"; es.add_system<LinearImplicitSystem> (system_name); es.get_system(system_name).add_variable("u", FIRST); es.init(); es.print_info(); const DofMap & dof_map = es.get_system(system_name).get_dof_map(); UniquePtr< NumericVector< Number > > x = es.get_system(system_name).solution->zero_clone(); PetscVector< Number > y( mesh.comm(), x->size() ); std::vector< dof_id_type > dof_indices; std::set<dof_id_type> some_dof_set; MeshBase::const_element_iterator el = mesh.active_local_elements_begin(); const MeshBase::const_element_iterator end_el = mesh.active_local_elements_end(); // create some dofs local to each processor for ( ; el != end_el ; ++el) { const Elem * elem = *el; dof_map.dof_indices (elem, dof_indices); if ( elem->centroid()(0) < 0. ) some_dof_set.insert( dof_indices.begin(), dof_indices.end() ); } // build a subvector local to each procoessor std::vector< dof_id_type > some_dofs( some_dof_set.begin(), some_dof_set.end() ); x->create_subvector( y, some_dofs ); std::cout << "PROC = " << mesh.comm().rank() << ": local size of some_dofs = " << some_dofs.size() << std::endl; std::cout << "PROC = " << mesh.comm().rank() << ": global size of y = " << y.size() << std::endl; std::cout << "PROC = " << mesh.comm().rank() << ": local size of y = " << y.local_size() << std::endl; std::cout << "PROC = " << mesh.comm().rank() << ": (first,last) local index of y = (" << y.first_local_index() << ", " << y.last_local_index() << ")" << std::endl; return 0; } The output that I get when running the program with mpirun -np 2 ./ex_create_subvector-opt --keep-cout is elem_dimensions()={2} spatial_dimension()=2 n_nodes()=121 n_local_nodes()=67 n_elem()=100 n_local_elem()=50 n_active_elem()=100 n_subdomains()=1 n_partitions()=2 n_processors()=2 n_threads()=1 processor_id()=0 Mesh Information: elem_dimensions()={2} spatial_dimension()=2 n_nodes()=121 n_local_nodes()=54 n_elem()=100 n_local_elem()=50 n_active_elem()=100 n_subdomains()=1 n_partitions()=2 n_processors()=2 n_threads()=1 processor_id()=1 EquationSystems n_systems()=1 System #0, "Poisson" Type "LinearImplicit" Variables="u" Finite Element Types="LAGRANGE", "JACOBI_20_00" Infinite Element Mapping="CARTESIAN" Approximation Orders="FIRST", "THIRD" n_dofs()=121 n_local_dofs()=67 n_constrained_dofs()=0 n_local_constrained_dofs()=0 n_vectors()=1 n_matrices()=1 DofMap Sparsity Average On-Processor Bandwidth <= 7.70248 Average Off-Processor Bandwidth <= 0.545455 Maximum On-Processor Bandwidth <= 11 Maximum Off-Processor Bandwidth <= 4 DofMap Constraints Number of DoF Constraints = 0 Number of Node Constraints = 0 EquationSystems n_systems()=1 System #0, "Poisson" Type "LinearImplicit" Variables="u" Finite Element Types="LAGRANGE", "JACOBI_20_00" Infinite Element Mapping="CARTESIAN" Approximation Orders="FIRST", "THIRD" n_dofs()=121 n_local_dofs()=54 n_constrained_dofs()=0 n_local_constrained_dofs()=0 n_vectors()=1 n_matrices()=1 DofMap Sparsity Average On-Processor Bandwidth <= 7.70248 Average Off-Processor Bandwidth <= 0.545455 Maximum On-Processor Bandwidth <= 11 Maximum Off-Processor Bandwidth <= 4 DofMap Constraints Number of DoF Constraints = 0 Number of Node Constraints = 0 PROC = 0: local size of some_dofs = 10 PROC = 0: global size of y = 121 PROC = 0: local size of y = 121 PROC = 0: (first,last) local index of y = (0, 121) PROC = 1: local size of some_dofs = 62 PROC = 1: global size of y = 121 PROC = 1: local size of y = 121 PROC = 1: (first,last) local index of y = (0, 121) Apparently, the vector y is not distributed correctly to the processors. Is this a bug? Best, Jonas ------------------------------------------------------------------------------ What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic patterns at an interface-level. Reveals which users, apps, and protocols are consuming the most bandwidth. Provides multi-vendor support for NetFlow, J-Flow, sFlow and other flows. Make informed decisions using capacity planning reports.http://sdm.link/zohodev2dev _______________________________________________ Libmesh-users mailing list Libmesh-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libmesh-users