const StaticMesh* MeshManager::GetMesh(const std::string& meshName) { auto meshIterator = m_MeshMap.find(meshName); if (m_MeshMap.end() == meshIterator) { // Attempt to load from the database. int offset = m_MeshDBIndex.OffsetOfMesh(meshName); if (-1 == offset) { return m_DefaultMesh.get(); } else { // We have the offset, we can now load the mesh from the HDD, and initialize its GPU form fseek(m_MeshDatabase, static_cast<long>(offset), SEEK_SET); StoredStaticMesh storedStaticMesh; storedStaticMesh.Load(m_MeshDatabase); std::unique_ptr<float[]> vertexArray(storedStaticMesh.GetVertexArray()); std::unique_ptr<float[]> texCoordArray(storedStaticMesh.GetTexCoordArray()); std::unique_ptr<float[]> normalArray(storedStaticMesh.GetNormalArray()); std::unique_ptr<uint32_t[]> indexArray(storedStaticMesh.GetIndexArray()); auto newMesh = new StaticMesh(storedStaticMesh.GetNumVertices(), std::move(vertexArray), std::move(texCoordArray), std::move(normalArray), storedStaticMesh.GetNumIndices(), std::move(indexArray)); std::unique_ptr<StaticMesh> staticMesh(newMesh); m_MeshMap.insert(std::make_pair(meshName, std::move(staticMesh))); return newMesh; } } else { return m_DefaultMesh.get(); } }
void test_field() { unsigned spatialDim = 3; stk::mesh::MetaData meta(spatialDim); stk::mesh::BulkData bulk(meta, MPI_COMM_WORLD); unsigned dimX = 10; unsigned dimY = 10; unsigned dimZ = 10; std::ostringstream mesh_spec; mesh_spec << "generated:"<<dimX<<"x"<<dimY<<"x"<<dimZ; stk::io::fill_mesh(mesh_spec.str(), bulk); ngp::StaticMesh staticMesh(bulk); double initialValue = 9.9; ngp::StaticField<double> scalarField(stk::topology::NODE_RANK, initialValue, bulk, meta.locally_owned_part()); stk::mesh::EntityVector nodes; stk::mesh::get_selected_entities(meta.locally_owned_part(), bulk.buckets(stk::topology::NODE_RANK), nodes); Kokkos::View<stk::mesh::Entity*> device_nodes("device_nodes", nodes.size()); Kokkos::View<stk::mesh::Entity*,Kokkos::HostSpace> host_nodes("host_nodes", nodes.size()); for(size_t i=0; i<nodes.size(); ++i) { host_nodes(i) = nodes[i]; } Kokkos::deep_copy(device_nodes, host_nodes); struct timeval begin,end; gettimeofday(&begin,NULL); int nrepeat = 500; double result = 0; for(int n=0; n<nrepeat; ++n) { result = 0; Kokkos::parallel_reduce(nodes.size(), KOKKOS_LAMBDA(int i, double& update) { update += scalarField.get(staticMesh, device_nodes(i), 0); }, result);