1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
/*=========================================================================
Program: Visualization Toolkit
Module: TestPStructuredGridConnectivity.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkCellData.h"
#include "vtkCellType.h"
#include "vtkDoubleArray.h"
#include "vtkExtentRCBPartitioner.h"
#include "vtkIdList.h"
#include "vtkIdTypeArray.h"
#include "vtkMPIController.h"
#include "vtkMPIUtilities.h"
#include "vtkMultiProcessController.h"
#include "vtkPUnstructuredGridConnectivity.h"
#include "vtkPointData.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
#include "vtkStructuredData.h"
#include "vtkTimerLog.h"
#include "vtkUnstructuredGrid.h"
#include "vtkUnstructuredGridWriter.h"
#include <sstream>
#include <string>
//#define DEBUG
#include "UnstructuredGhostZonesCommon.h"
//------------------------------------------------------------------------------
// Program main
int TestPUnstructuredGridConnectivity(int argc, char* argv[])
{
int rc = 0;
vtkTimerLog* timer = vtkTimerLog::New();
// STEP 0: Initialize
vtkMPIController* cntrl = vtkMPIController::New();
cntrl->Initialize( &argc, &argv, 0 );
vtkMultiProcessController::SetGlobalController( cntrl );
global::Rank = cntrl->GetLocalProcessId();
global::NRanks = cntrl->GetNumberOfProcesses();
// STEP 1: Generate grid in parallel in each process
global::Grid = vtkUnstructuredGrid::New();
GenerateDataSet();
// STEP 2: Generate ghost zones
vtkMPIUtilities::Printf(cntrl,"[INFO]: Building ghost zones...");
vtkPUnstructuredGridConnectivity* ghostGen =
vtkPUnstructuredGridConnectivity::New();
ghostGen->SetController(cntrl);
ghostGen->RegisterGrid(global::Grid);
timer->StartTimer();
ghostGen->BuildGhostZoneConnectivity();
timer->StopTimer();
double ellapsed = timer->GetElapsedTime();
vtkMPIUtilities::Printf(cntrl,"[DONE]\n");
// get some performance statistics
double minBuildGhostZonesTime = 0.0;
double maxBuildGhostZonesTime = 0.0;
double avgBuildGhostZonesTime = 0.0;
cntrl->Reduce(&ellapsed,&minBuildGhostZonesTime,1,vtkCommunicator::MIN_OP,0);
cntrl->Reduce(&ellapsed,&maxBuildGhostZonesTime,1,vtkCommunicator::MAX_OP,0);
cntrl->Reduce(&ellapsed,&avgBuildGhostZonesTime,1,vtkCommunicator::SUM_OP,0);
avgBuildGhostZonesTime /= static_cast<double>(cntrl->GetNumberOfProcesses());
vtkMPIUtilities::Printf(
cntrl,"-- Ellapsed Time: min=%f, avg=%f, max=%f\n",
minBuildGhostZonesTime,avgBuildGhostZonesTime,maxBuildGhostZonesTime);
// STEP 3: Update ghost zones
std::ostringstream grdfname; // input grid name at each iteration for I/O
std::ostringstream ghostfname; // ghosted grid name at each iteration for I/O
for(int i=0; i < 2; ++i)
{
vtkUnstructuredGrid* ghostGrid = vtkUnstructuredGrid::New();
grdfname.clear();
grdfname.str("");
grdfname << "INITIAL-T" << i;
ghostfname.clear();
ghostfname.str("");
ghostfname << "GHOSTED-T" << i;
// update grid in this time-step
UpdateGrid(i);
#ifdef DEBUG
WriteDataSet(Grid,grdfname.str());
#endif
vtkMPIUtilities::Printf(cntrl,"[INFO]: iteration=%d\n",i);
vtkMPIUtilities::Printf(cntrl,"[INFO]: Update ghost zones...");
timer->StartTimer();
ghostGen->UpdateGhosts();
timer->StopTimer();
ellapsed = timer->GetElapsedTime();
vtkMPIUtilities::Printf(cntrl,"[DONE]\n");
// get some performance statistics
double minGhostUpdateTime = 0.0;
double maxGhostUpdateTime = 0.0;
double avgGhostUpdateTime = 0.0;
cntrl->Reduce(&ellapsed,&minGhostUpdateTime,1,vtkCommunicator::MIN_OP,0);
cntrl->Reduce(&ellapsed,&maxGhostUpdateTime,1,vtkCommunicator::MAX_OP,0);
cntrl->Reduce(&ellapsed,&avgGhostUpdateTime,1,vtkCommunicator::SUM_OP,0);
avgGhostUpdateTime /= static_cast<double>(cntrl->GetNumberOfProcesses());
vtkMPIUtilities::Printf(
cntrl,"-- Ellapsed Time: min=%f, avg=%f, max=%f\n",
minGhostUpdateTime,avgGhostUpdateTime,maxGhostUpdateTime);
ghostGrid->DeepCopy(ghostGen->GetGhostedGrid());
#ifdef DEBUG
assert("pre: ghost grid should not be NULL!" && (ghostGrid != NULL) );
WriteDataSet(ghostGrid,ghostfname.str());
#endif
rc += CheckGrid(ghostGrid,i);
ghostGrid->Delete();
}
// STEP 5: Delete the ghost generator
timer->Delete();
ghostGen->Delete();
global::Grid->Delete();
cntrl->Finalize();
cntrl->Delete();
return( rc );
}
|