Commit 9b35cea5 authored by Berk Geveci's avatar Berk Geveci
Browse files

ENH: Removed examples for deprecated classes.

parent 5882b726
INCLUDE_REGULAR_EXPRESSION("^(lex|vtk|png|j|Task|Pipe).*$")
IF (CMAKE_USE_PTHREADS)
SET(VTK_HAS_THREADS 1)
ENDIF (CMAKE_USE_PTHREADS)
IF (CMAKE_USE_SPROC)
SET(VTK_HAS_THREADS 1)
ENDIF (CMAKE_USE_SPROC)
IF (CMAKE_USE_WIN32_THREADS)
SET(VTK_HAS_THREADS 1)
ENDIF (CMAKE_USE_WIN32_THREADS)
IF (VTK_HAS_THREADS OR VTK_USE_MPI)
IF (VTK_USE_MPI)
IF (VTK_USE_RENDERING)
ADD_EXECUTABLE(ParallelIso ParallelIso.cxx)
TARGET_LINK_LIBRARIES(ParallelIso vtkParallel vtkHybrid)
......@@ -20,19 +10,11 @@ IF (VTK_HAS_THREADS OR VTK_USE_MPI)
ENDIF (VTK_USE_RENDERING)
SET(TaskPara_SRCS TaskParallelism.cxx task1.cxx task2.cxx)
SET(TaskParaPorts_SRCS TaskParallelismWithPorts.cxx task3.cxx task4.cxx)
SET(PipePara_SRCS PipelineParallelism.cxx pipe1.cxx pipe2.cxx)
ADD_EXECUTABLE(TaskParallelism ${TaskPara_SRCS})
ADD_EXECUTABLE(TaskParallelismWithPorts ${TaskParaPorts_SRCS})
ADD_EXECUTABLE(PipelineParallelism ${PipePara_SRCS})
TARGET_LINK_LIBRARIES (TaskParallelism vtkParallel)
TARGET_LINK_LIBRARIES (TaskParallelismWithPorts vtkParallel)
TARGET_LINK_LIBRARIES (PipelineParallelism vtkParallel)
IF(APPLE)
TARGET_LINK_LIBRARIES(TaskParallelism "-framework Carbon")
TARGET_LINK_LIBRARIES(TaskParallelismWithPorts "-framework Carbon")
TARGET_LINK_LIBRARIES(PipelineParallelism "-framework Carbon")
ENDIF(APPLE)
ENDIF (VTK_HAS_THREADS OR VTK_USE_MPI)
ENDIF (VTK_USE_MPI)
......@@ -12,50 +12,75 @@
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// This program demonstrates the use ports by setting up a simple
// pipeline. All processes create an identical pipeline:
// vtkImageReader -> vtkContourFilter -> vtkElevationFilter
// In addition, the first (root) process creates n input ports
// (where n=nProcs-1), each attached to an output port on the other
// processes. It then appends the polygonal output from all input
// ports and it's own pipeline and renders the result ISO_NUM times,
// each time setting a different scalar value to be contoured.
// This example demonstrates the use of data parallelism in VTK. The
// pipeline ( vtkImageReader -> vtkContourFilter -> vtkElevationFilter )
// is created in parallel and each process is assigned 1 piece to process.
// All satellite processes send the result to the first process which
// collects and renders them.
#include "vtkActor.h"
#include "vtkAppendPolyData.h"
#include "vtkCamera.h"
#include "vtkConeSource.h"
#include "vtkContourFilter.h"
#include "vtkDataSet.h"
#include "vtkElevationFilter.h"
#include "vtkImageData.h"
#include "vtkImageReader.h"
#include "vtkInputPort.h"
#include "vtkMath.h"
#include "vtkMultiProcessController.h"
#include "vtkOutputPort.h"
#include "vtkMPIController.h"
#include "vtkParallelFactory.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkTestUtilities.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkTestUtilities.h"
#include "vtkTimerLog.h"
#include "vtkWindowToImageFilter.h"
#include "vtkImageData.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkInformation.h"
#include "vtkDebugLeaks.h"
#include <mpi.h>
static const float ISO_START=4250.0;
static const float ISO_STEP=-1250.0;
static const int ISO_NUM=3;
// Just pick a tag which is available
static const int ISO_VALUE_RMI_TAG=300;
static const int PORT_TAG=999;
static const int ISO_OUTPUT_TAG=301;
struct ParallelIsoArgs_tmp
{
int* retVal;
int argc;
char** argv;
};
struct ParallelIsoRMIArgs_tmp
{
vtkContourFilter* ContourFilter;
vtkMultiProcessController* Controller;
vtkElevationFilter* Elevation;
};
// call back to set the iso surface value.
void SetIsoValueRMI(void *localArg, void* vtkNotUsed(remoteArg),
int vtkNotUsed(remoteArgLen), int vtkNotUsed(id))
{
ParallelIsoRMIArgs_tmp* args = (ParallelIsoRMIArgs_tmp*)localArg;
float val;
vtkContourFilter *iso = reinterpret_cast<vtkContourFilter *>(localArg);
vtkContourFilter *iso = args->ContourFilter;
val = iso->GetValue(0);
iso->SetValue(0, val + ISO_STEP);
args->Elevation->Update();
vtkMultiProcessController* contrl = args->Controller;
contrl->Send(args->Elevation->GetOutput(), 0, ISO_OUTPUT_TAG);
}
......@@ -67,8 +92,7 @@ void MyMain( vtkMultiProcessController *controller, void *arg )
vtkElevationFilter *elev;
int myid, numProcs;
float val;
int numTris;
char* fname = reinterpret_cast<char*>(arg);
ParallelIsoArgs_tmp* args = reinterpret_cast<ParallelIsoArgs_tmp*>(arg);
// Obtain the id of the running process and the total
// number of processes
......@@ -77,11 +101,14 @@ void MyMain( vtkMultiProcessController *controller, void *arg )
// Create the reader, the data file name might have
// to be changed depending on where the data files are.
char* fname = vtkTestUtilities::ExpandDataFileName(args->argc, args->argv,
"Data/headsq/quarter");
reader = vtkImageReader::New();
reader->SetDataByteOrderToLittleEndian();
reader->SetDataExtent(0, 63, 0, 63, 1, 93);
reader->SetFilePrefix(fname);
reader->SetDataSpacing(3.2, 3.2, 1.5);
delete[] fname;
// Iso-surface.
iso = vtkContourFilter::New();
......@@ -93,136 +120,98 @@ void MyMain( vtkMultiProcessController *controller, void *arg )
// Compute a different color for each process.
elev = vtkElevationFilter::New();
elev->SetInput(iso->GetOutput());
vtkMath::RandomSeed(myid * 100);
val = vtkMath::Random();
val = (myid+1) / static_cast<float>(numProcs);
elev->SetScalarRange(val, val+0.001);
// Tell the pipeline which piece we want to update.
vtkStreamingDemandDrivenPipeline* exec =
vtkStreamingDemandDrivenPipeline::SafeDownCast(elev->GetExecutive());
exec->SetUpdateNumberOfPieces(exec->GetOutputInformation(0), numProcs);
exec->SetUpdatePiece(exec->GetOutputInformation(0), myid);
if (myid != 0)
{
// If I am not the root process
ParallelIsoRMIArgs_tmp args;
args.ContourFilter = iso;
args.Controller = controller;
args.Elevation = elev;
// Satellite process! Send data through port.
vtkOutputPort *upPort = vtkOutputPort::New();
// Last, set up a RMI call back to change the iso surface value.
// This is done so that the root process can let this process
// know that it wants the contour value to change.
controller->AddRMI(SetIsoValueRMI, (void *)iso, ISO_VALUE_RMI_TAG);
// connect the port to the output of the pipeline
upPort->SetInput(elev->GetPolyDataOutput());
// Multiple ports can go through the same connection.
// This is used to differentiate ports
upPort->SetTag(PORT_TAG);
// Loop which processes RMI requests.
// Use vtkMultiProcessController::BREAK_RMI_TAG to break it.
// The root process will send an ISO_VALUE_RMI_TAG to make this
// process change it's contour value.
upPort->WaitForUpdate();
// We are done. Clean up.
upPort->Delete();
controller->AddRMI(SetIsoValueRMI, (void *)&args, ISO_VALUE_RMI_TAG);
controller->ProcessRMIs();
}
else
{
// If I am the root process
int i, j;
// Create the rendering part of the pipeline
vtkAppendPolyData *app = vtkAppendPolyData::New();
vtkInputPort *downPort;
vtkRenderer *ren = vtkRenderer::New();
vtkRenderWindow *renWindow = vtkRenderWindow::New();
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
vtkActor *actor = vtkActor::New();
vtkTimerLog *timer = vtkTimerLog::New();
vtkCamera *cam = vtkCamera::New();
// Add my pipeline's output to the append filter
app->AddInput(elev->GetPolyDataOutput());
// ###################### important ####################
// # This tells the append filter to request pieces from
// # each of its inputs. Since each of its inputs comes from
// # a different process, each process generates a separate
// # piece of the data (data parallelism).
// # If this is not used, all processes will iso-surface
// # all the data.
app->ParallelStreamingOn();
// This is the main thread: Collect the data and render it.
for (i = 1; i < numProcs; ++i)
{
downPort = vtkInputPort::New();
downPort->SetRemoteProcessId(i);
// Multiple ports can go through the same connection.
// This is used to differentiate ports
downPort->SetTag(PORT_TAG);
app->AddInput(downPort->GetPolyDataOutput());
// Reference already incremented by AddInput(). Delete()
// will only decrement the count, not destroy the object.
// The ports will be destroyed when the append filter
// goes away.
downPort->Delete();
downPort = NULL;
}
// Create the rendering part of the pipeline
renWindow->AddRenderer(ren);
iren->SetRenderWindow(renWindow);
ren->SetBackground(0.9, 0.9, 0.9);
renWindow->SetSize( 400, 400);
mapper->SetInput(app->GetOutput());
actor->SetMapper(mapper);
ren->AddActor(actor);
cam->SetFocalPoint(100, 100, 65);
cam->SetPosition(100, 450, 65);
cam->SetViewUp(0, 0, -1);
cam->SetViewAngle(30);
cam->SetClippingRange(177.0, 536.0);
ren->SetActiveCamera(cam);
// loop through some iso surface values.
for (j = 0; j < ISO_NUM; ++j)
for (int j = 0; j < ISO_NUM; ++j)
{
// set the local value
SetIsoValueRMI((void*)iso, NULL, 0, 0);
for (i = 1; i < numProcs; ++i)
iso->SetValue(0, iso->GetValue(0) + ISO_STEP);
elev->Update();
for (int i = 1; i < numProcs; ++i)
{
// trigger the RMI to change the iso surface value.
controller->TriggerRMI(i, ISO_VALUE_RMI_TAG);
}
// Time the rendering. Note that the execution on all processes
// start only after Update()
timer->StartTimer();
app->Update();
timer->StopTimer();
numTris = iso->GetOutput()->GetNumberOfCells();
val = iso->GetValue(0);
cerr << "Update " << val << " took " << timer->GetElapsedTime()
<< " seconds to produce " << numTris << " triangles\n";
// now render the results
renWindow->Render();
for (int i = 1; i < numProcs; ++i)
{
vtkPolyData* pd = vtkPolyData::New();
controller->Receive(pd, i, ISO_OUTPUT_TAG);
if (j == ISO_NUM - 1)
{
app->AddInput(pd);
}
pd->Delete();
}
}
// Tell the other processors to stop processing RMIs.
for (i = 1; i < numProcs; ++i)
for (int i = 1; i < numProcs; ++i)
{
controller->TriggerRMI(i, vtkMultiProcessController::BREAK_RMI_TAG);
}
vtkPolyData* outputCopy = vtkPolyData::New();
outputCopy->ShallowCopy(elev->GetOutput());
app->AddInput(outputCopy);
outputCopy->Delete();
app->Update();
renWindow->Render();
*(args->retVal) =
vtkRegressionTester::Test(args->argc, args->argv, renWindow, 10);
if ( *(args->retVal) == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
// Clean up
app->Delete();
ren->Delete();
......@@ -231,7 +220,6 @@ void MyMain( vtkMultiProcessController *controller, void *arg )
mapper->Delete();
actor->Delete();
cam->Delete();
timer->Delete();
}
// clean up objects in all processes.
......@@ -243,36 +231,39 @@ void MyMain( vtkMultiProcessController *controller, void *arg )
int main( int argc, char* argv[] )
{
vtkMultiProcessController *controller;
// This is here to avoid false leak messages from vtkDebugLeaks when
// using mpich. It appears that the root process which spawns all the
// main processes waits in MPI_Init() and calls exit() when
// the others are done, causing apparent memory leaks for any objects
// created before MPI_Init().
MPI_Init(&argc, &argv);
// Note that this will create a vtkMPIController if MPI
// is configured, vtkThreadedController otherwise.
controller = vtkMultiProcessController::New();
controller->Initialize(&argc, &argv);
// Use this method to get the place of the data directory.
char* fname = vtkTestUtilities::ExpandDataFileName(argc, argv,
"Data/headsq/quarter");
controller->SetSingleMethod(MyMain, (void*)fname );
// When using MPI, the number of processes is determined
// by the external program which launches this application.
// However, when using threads, we need to set it ourselves.
if (controller->IsA("vtkThreadedController"))
{
// Set the number of processes to 2 for this example.
controller->SetNumberOfProcesses(2);
}
vtkMPIController* controller = vtkMPIController::New();
controller->Initialize(&argc, &argv, 1);
vtkParallelFactory* pf = vtkParallelFactory::New();
vtkObjectFactory::RegisterFactory(pf);
pf->Delete();
// Added for regression test.
// ----------------------------------------------
int retVal = 1;
ParallelIsoArgs_tmp args;
args.retVal = &retVal;
args.argc = argc;
args.argv = argv;
// ----------------------------------------------
controller->SetSingleMethod(MyMain, &args);
controller->SingleMethodExecute();
delete[] fname;
controller->Finalize();
controller->Delete();
return 0;
return !retVal;
}
......
......@@ -89,7 +89,7 @@ int main( int argc, char* argv[] )
// Note that this will create a vtkMPIController if MPI
// is configured, vtkThreadedController otherwise.
vtkMultiProcessController* controller = vtkMultiProcessController::New();
vtkMPIController* controller = vtkMPIController::New();
controller->Initialize(&argc, &argv);
// When using MPI, the number of processes is determined
......
......@@ -15,7 +15,7 @@
#ifndef __TASKPARA_H
#define __TASKPARA_H
#include "vtkMultiProcessController.h"
#include "vtkMPIController.h"
#include "vtkRTAnalyticSource.h"
#include "vtkFieldDataToAttributeDataFilter.h"
#include "vtkAttributeDataToFieldDataFilter.h"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment