Skip to content

Commit

Permalink
Merge pull request #6068 from trilinos/panzer_staticprofile
Browse files Browse the repository at this point in the history
panzer:  change dynamic profile Tpetra::CrsGraph construction to static profile for #5602
  • Loading branch information
rppawlo authored Oct 15, 2019
2 parents c4c4a01 + 2233464 commit a133adb
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,15 @@ buildNodeToCellMatrix(const Teuchos::RCP<const Teuchos::Comm<int> > & comm,
RCP<crs_type> cell_to_node;
{
PANZER_FUNC_TIME_MONITOR_DIFF("Build matrix",BuildMatrix);
// The matrix is indexed by (global cell, global node) = local node
cell_to_node = rcp(new crs_type(cell_map,0));

// fill in the cell to node matrix
const unsigned int num_local_cells = owned_cells_to_nodes.extent(0);
const unsigned int num_nodes_per_cell = owned_cells_to_nodes.extent(1);

// The matrix is indexed by (global cell, global node) = local node
cell_to_node = rcp(new crs_type(cell_map,num_nodes_per_cell,
Tpetra::StaticProfile));

std::vector<panzer::LocalOrdinal> local_node_indexes(num_nodes_per_cell);
std::vector<panzer::GlobalOrdinal> global_node_indexes(num_nodes_per_cell);
for(unsigned int i=0;i<num_local_cells;i++) {
Expand Down
24 changes: 23 additions & 1 deletion packages/panzer/disc-fe/src/Panzer_L2Projection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,34 @@ namespace panzer {
ghostedSourceMap = rcp(new MapType(Teuchos::OrdinalTraits<panzer::GlobalOrdinal>::invalid(),indices,0,comm_));
}

RCP<GraphType> ghostedGraph = rcp(new GraphType(ghostedTargetMap,ghostedSourceMap,0));

// Now insert the non-zero pattern per row
// count number of entries per row; required by CrsGraph constructor
std::vector<size_t> nEntriesPerRow(ghostedTargetMap->getNodeNumElements(),0);
std::vector<std::string> elementBlockIds;
targetGlobalIndexer_->getElementBlockIds(elementBlockIds);
std::vector<std::string>::const_iterator blockItr;
for (blockItr=elementBlockIds.begin();blockItr!=elementBlockIds.end();++blockItr) {
std::string blockId = *blockItr;
const std::vector<panzer::LocalOrdinal> & elements = targetGlobalIndexer_->getElementBlock(blockId);

std::vector<panzer::GlobalOrdinal> row_gids;
std::vector<panzer::GlobalOrdinal> col_gids;

for(std::size_t elmt=0;elmt<elements.size();elmt++) {
targetGlobalIndexer_->getElementGIDs(elements[elmt],row_gids);
sourceGlobalIndexer.getElementGIDs(elements[elmt],col_gids);
for(std::size_t row=0;row<row_gids.size();row++) {
panzer::LocalOrdinal lid =
ghostedTargetMap->getLocalElement(row_gids[row]);
nEntriesPerRow[lid] += col_gids.size();
}
}
}

Teuchos::ArrayView<const size_t> nEntriesPerRowView(nEntriesPerRow);
RCP<GraphType> ghostedGraph = rcp(new GraphType(ghostedTargetMap,ghostedSourceMap,nEntriesPerRowView,Tpetra::StaticProfile));

for (blockItr=elementBlockIds.begin();blockItr!=elementBlockIds.end();++blockItr) {
std::string blockId = *blockItr;
const std::vector<panzer::LocalOrdinal> & elements = targetGlobalIndexer_->getElementBlock(blockId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1001,8 +1001,6 @@ buildTpetraGhostedGraph(int i,int j) const
RCP<const MapType> map_i = getGhostedMap(i);
RCP<const MapType> map_j = getGhostedMap(j);

RCP<CrsGraphType> graph = rcp(new CrsGraphType(map_i,map_j,0));

std::vector<std::string> elementBlockIds;

Teuchos::RCP<const GlobalIndexer> rowProvider, colProvider;
Expand All @@ -1013,8 +1011,37 @@ buildTpetraGhostedGraph(int i,int j) const
gidProviders_[0]->getElementBlockIds(elementBlockIds); // each sub provider "should" have the
// same element blocks

// graph information about the mesh
// Count number of entries in each row of graph; needed for graph constructor
std::vector<size_t> nEntriesPerRow(map_i->getNodeNumElements(), 0);
std::vector<std::string>::const_iterator blockItr;
for(blockItr=elementBlockIds.begin();blockItr!=elementBlockIds.end();++blockItr) {
std::string blockId = *blockItr;
// grab elements for this block
const std::vector<LocalOrdinalT> & elements = gidProviders_[0]->getElementBlock(blockId); // each sub provider "should" have the
// same elements in each element block

// get information about number of indicies
std::vector<GlobalOrdinalT> row_gids;
std::vector<GlobalOrdinalT> col_gids;

// loop over the elemnts
for(std::size_t elmt=0;elmt<elements.size();elmt++) {

rowProvider->getElementGIDs(elements[elmt],row_gids);
colProvider->getElementGIDs(elements[elmt],col_gids);
for(std::size_t row=0;row<row_gids.size();row++) {
LocalOrdinalT lid = map_i->getLocalElement(row_gids[row]);
nEntriesPerRow[lid] += col_gids.size();
}
}
}
Teuchos::ArrayView<const size_t> nEntriesPerRowView(nEntriesPerRow);
RCP<CrsGraphType> graph = rcp(new CrsGraphType(map_i,map_j, nEntriesPerRowView,
Tpetra::StaticProfile));



// graph information about the mesh
for(blockItr=elementBlockIds.begin();blockItr!=elementBlockIds.end();++blockItr) {
std::string blockId = *blockItr;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,6 @@ buildGhostedGraph() const
// build the map and allocate the space for the graph
Teuchos::RCP<MapType> rMap = getGhostedMap();
Teuchos::RCP<MapType> cMap = getGhostedColMap();
Teuchos::RCP<CrsGraphType> graph = Teuchos::rcp(new CrsGraphType(rMap,cMap,0));

std::vector<std::string> elementBlockIds;
gidProvider_->getElementBlockIds(elementBlockIds);
Expand All @@ -675,6 +674,9 @@ buildGhostedGraph() const
const bool han = conn_mgr.is_null() ? false : conn_mgr->hasAssociatedNeighbors();

// graph information about the mesh
// Count number of entries per graph row; needed for graph constructor
std::vector<size_t> nEntriesPerRow(rMap->getNodeNumElements(), 0);

std::vector<std::string>::const_iterator blockItr;
for(blockItr=elementBlockIds.begin();blockItr!=elementBlockIds.end();++blockItr) {
std::string blockId = *blockItr;
Expand All @@ -686,6 +688,44 @@ buildGhostedGraph() const
std::vector<GlobalOrdinalT> gids;
std::vector<GlobalOrdinalT> col_gids;

// loop over the elemnts
for(std::size_t i=0;i<elements.size();i++) {
gidProvider_->getElementGIDs(elements[i],gids);

colGidProvider->getElementGIDs(elements[i],col_gids);
if (han) {
const std::vector<LocalOrdinalT>& aes = conn_mgr->getAssociatedNeighbors(elements[i]);
for (typename std::vector<LocalOrdinalT>::const_iterator eit = aes.begin();
eit != aes.end(); ++eit) {
std::vector<GlobalOrdinalT> other_col_gids;
colGidProvider->getElementGIDs(*eit, other_col_gids);
col_gids.insert(col_gids.end(), other_col_gids.begin(), other_col_gids.end());
}
}

for(std::size_t j=0;j<gids.size();j++){
LocalOrdinalT lid = rMap->getLocalElement(gids[j]);
nEntriesPerRow[lid] += col_gids.size();
}
}
}

Teuchos::ArrayView<const size_t> nEntriesPerRowView(nEntriesPerRow);
Teuchos::RCP<CrsGraphType> graph = Teuchos::rcp(new CrsGraphType(rMap,cMap,
nEntriesPerRowView,
Tpetra::StaticProfile));

// Now insert entries into the graph
for(blockItr=elementBlockIds.begin();blockItr!=elementBlockIds.end();++blockItr) {
std::string blockId = *blockItr;

// grab elements for this block
const std::vector<LocalOrdinalT> & elements = gidProvider_->getElementBlock(blockId);

// get information about number of indicies
std::vector<GlobalOrdinalT> gids;
std::vector<GlobalOrdinalT> col_gids;

// loop over the elemnts
for(std::size_t i=0;i<elements.size();i++) {
gidProvider_->getElementGIDs(elements[i],gids);
Expand Down

0 comments on commit a133adb

Please sign in to comment.