// Copyright 2002 - 2008, 2010, 2011 National Technology Engineering // Solutions of Sandia, LLC (NTESS). Under the terms of Contract // DE-NA0003525 with NTESS, the U.S. Government retains certain rights // in this software. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of NTESS nor the names of its contributors // may be used to endorse or promote products derived from this // software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // for StkMeshIoBroker #include // for count_entities #include #include #include #include #include namespace { double initial_value1[3] = {-1, 2, -0.3}; void createNodalVectorField(stk::mesh::MetaData& meshMetaData, const std::string &fieldName, const std::string &partName) { stk::mesh::Field &field1 = meshMetaData.declare_field(stk::topology::NODE_RANK, fieldName); stk::mesh::Part* part = meshMetaData.get_part(partName); ASSERT_TRUE(part != nullptr)<(stk::mesh::field_data(*fields[f], bucket)); unsigned flen = stk::mesh::field_scalars_per_entity(*fields[f], bucket); for(size_t n=0; n(f); } } } return num_nodes; } void createMetaAndBulkData(stk::io::StkMeshIoBroker &exodusFileReader, const std::string& genMeshSpec, unsigned numBlocks, unsigned numFields) { std::string exodusFileName = stk::unit_test_util::get_option("-i", "NO_FILE_SPECIFIED"); if (exodusFileName == "NO_FILE_SPECIFIED") { exodusFileName = genMeshSpec; } exodusFileReader.add_mesh_database(exodusFileName, stk::io::READ_MESH); stk::ParallelMachine communicator = MPI_COMM_WORLD; int myProc = stk::parallel_machine_rank(communicator); if (myProc==0) { std::cerr << "Starting To Read Mesh: " << exodusFileName << std::endl; } exodusFileReader.create_input_mesh(); std::shared_ptr stkMeshMetaData = exodusFileReader.meta_data_ptr(); if (numBlocks==1) { createNodalVectorFields(*stkMeshMetaData, "nodalField", numFields, "{universal}"); } else { stk::performance_tests::setup_multiple_blocks(*stkMeshMetaData, numBlocks); stk::mesh::PartVector blockParts; stk::mesh::fill_element_block_parts(*stkMeshMetaData, stk::topology::HEX_8, blockParts); for(const stk::mesh::Part* part : blockParts) { std::string fieldBaseName = part->name()+"nodalField"; createNodalVectorFields(*stkMeshMetaData, fieldBaseName, numFields, part->name()); } } stkMeshMetaData->commit(); std::shared_ptr arg_bulk_data = stk::mesh::MeshBuilder(MPI_COMM_WORLD).set_aura_option(stk::mesh::BulkData::AUTO_AURA).create(stkMeshMetaData); exodusFileReader.set_bulk_data(arg_bulk_data); stk::mesh::BulkData& stkMeshBulkData = *arg_bulk_data; bool delay_field_data_allocation = true; exodusFileReader.populate_mesh(delay_field_data_allocation); exodusFileReader.populate_field_data(); size_t num_ghostings = stkMeshBulkData.ghostings().size(); std::vector num_ghost_nodes(num_ghostings,0); for (size_t ghost_i = 0 ; ghost_i < num_ghostings ; ++ghost_i) { num_ghost_nodes[ghost_i] = setFieldData(stkMeshBulkData, stkMeshBulkData.ghosting_part(*stkMeshBulkData.ghostings()[ghost_i])); } for(int i=0; iname() << " nodes: " << num_ghost_nodes[ghost_i] << std::endl; } } stk::parallel_machine_barrier(MPI_COMM_WORLD); std::cerr << std::flush; stk::parallel_machine_barrier(MPI_COMM_WORLD); } if (myProc==0) { std::cerr << "Finished Reading Mesh" << std::endl; } stk::mesh::Selector allEntities = stkMeshMetaData->universal_part(); std::vector entityCounts; stk::mesh::count_entities(allEntities, stkMeshBulkData, entityCounts); size_t numElements = entityCounts[stk::topology::ELEMENT_RANK]; size_t numNodes = entityCounts[stk::topology::NODE_RANK]; if (myProc==0) { std::cerr << "Number of elements: " << numElements << std::endl; std::cerr << "Number of nodes: " << numNodes << std::endl; } } void createNgpFields(stk::mesh::BulkData& bulk) { auto stkFields = bulk.mesh_meta_data().get_fields(); for(auto stkField : stkFields) { stk::mesh::get_updated_ngp_field(*stkField); } } template void set_modify_on_device(std::vector*> ngpFields) { for(auto ngpField : ngpFields) { ngpField->modify_on_device(); } } void addPartToGhosting(stk::mesh::BulkData & bulk, const std::string & partName, stk::mesh::Ghosting& ghost) { const int numProcs = bulk.parallel_size(); const int myProc = bulk.parallel_rank(); stk::mesh::MetaData &meta = bulk.mesh_meta_data(); std::vector entities_to_ghost; stk::mesh::Selector surface_selector = *meta.get_part(partName) & meta.locally_owned_part(); stk::mesh::EntityVector surface_nodes; stk::mesh::get_selected_entities(surface_selector,bulk.buckets(stk::topology::NODE_RANK), surface_nodes); const int next_proc = (myProc+1)%numProcs; for (size_t i=0 ; iname() << " nodes: " << num_nodes << std::endl; } std::cerr << oss.str() << std::endl; const int my_proc = mesh.parallel_rank(); if (my_proc == 0) { std::cerr << "Calling communicate_field_data " << num_iters << " times"< const_fields(fields.size()); for(size_t i=0; i const_fields(fields.size()); for(size_t i=0; i*> ngpFields; for(auto field : fields) { ngpFields.push_back(&stk::mesh::get_updated_ngp_field(*field)); } const unsigned NUM_RUNS = 5; for (unsigned j = 0; j < NUM_RUNS; j++) { stk::parallel_machine_barrier(mesh.parallel()); batchTimer.start_batch_timer(); for(int iter=0; iter(ngpFields); } stk::mesh::communicate_field_data(mesh, ngpFields, true); } batchTimer.stop_batch_timer(); } batchTimer.print_batch_timing(num_iters); } TEST(CommunicateFieldData, copy_to_all) { stk::ParallelMachine comm = MPI_COMM_WORLD; if (stk::parallel_machine_size(comm) < 2) { GTEST_SKIP(); } test_communicate_field_data_all_ghosting(comm, 300); } TEST(CommunicateFieldData, Ghosting) { stk::ParallelMachine communicator = MPI_COMM_WORLD; int numProcs = stk::parallel_machine_size(communicator); if (numProcs < 2) { return; } const unsigned numBlocks = 1; const unsigned numFields = 8; test_communicate_field_data_ghosting(communicator, numBlocks, numFields, 1000); } TEST(CommunicateFieldData, Ghosting_MultiBlock) { stk::ParallelMachine communicator = MPI_COMM_WORLD; int numProcs = stk::parallel_machine_size(communicator); if (numProcs < 2) { return; } const unsigned numBlocks = 1; const unsigned numFields = 8; test_communicate_field_data_ghosting(communicator, numBlocks, numFields, 300); } TEST(CommunicateFieldData, NgpGhosting) { if (stk::parallel_machine_size(MPI_COMM_WORLD) < 2) { GTEST_SKIP(); } int iter = stk::unit_test_util::get_command_line_option("-t", 1000); bool syncToHostEveryIter = stk::unit_test_util::get_command_line_option("-h", false); test_communicate_field_data_ngp_ghosting(iter, syncToHostEveryIter); } }