Commit 2a3b0cca authored by Utkarsh Ayachit's avatar Utkarsh Ayachit
Browse files

vtkMultiProcessController: add API to reduce bounds

Add API to vtkMultiProcessController to reduce bounds, an operation that
we commonly to in the VTK world.
parent 254b08fe
......@@ -15,20 +15,19 @@
// This will be the default.
#include "vtkMultiProcessController.h"
#include "vtkBoundingBox.h"
#include "vtkByteSwap.h"
#include "vtkCollection.h"
#include "vtkCommand.h"
#include "vtkDummyController.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkOutputWindow.h"
#include "vtkProcess.h"
#include "vtkProcessGroup.h"
#include "vtkSubCommunicator.h"
#include "vtkToolkits.h"
#include "vtkProcess.h"
#include "vtkSmartPointer.h"
#include "vtkWeakPointer.h"
#define VTK_CREATE(type, name) \
vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
#include <list>
#include <unordered_map>
......@@ -329,7 +328,7 @@ vtkMultiProcessController *vtkMultiProcessController::PartitionController(
partitionIds.insert(iter, j);
}
// Copy list into process group.
VTK_CREATE(vtkProcessGroup, group);
vtkNew<vtkProcessGroup> group;
group->Initialize(this);
group->RemoveAllProcessIds();
for (std::list<int>::iterator iter = partitionIds.begin();
......@@ -768,6 +767,68 @@ void vtkMultiProcessController::ProcessRMI(int remoteProcessId,
(*citer->Function)(citer->LocalArgument, arg, argLength, remoteProcessId);
}
}
//----------------------------------------------------------------------------
int vtkMultiProcessController::Reduce(
const vtkBoundingBox& sendBuffer, vtkBoundingBox& recvBuffer, int destProcessId)
{
if (this->GetNumberOfProcesses() <= 1)
{
recvBuffer = sendBuffer;
return 1;
}
double send_min[3] = { VTK_DOUBLE_MAX, VTK_DOUBLE_MAX, VTK_DOUBLE_MAX };
double send_max[3] = { VTK_DOUBLE_MIN, VTK_DOUBLE_MIN, VTK_DOUBLE_MIN };
if (sendBuffer.IsValid())
{
sendBuffer.GetMinPoint(send_min);
sendBuffer.GetMaxPoint(send_max);
}
double recv_min[3], recv_max[3];
if (this->Reduce(send_min, recv_min, 3, vtkCommunicator::MIN_OP, destProcessId))
{
if (this->Reduce(send_max, recv_max, 3, vtkCommunicator::MAX_OP, destProcessId))
{
if (this->GetLocalProcessId() == destProcessId)
{
recvBuffer.SetMinPoint(recv_min);
recvBuffer.SetMaxPoint(recv_max);
}
return 1;
}
}
return 0;
}
//----------------------------------------------------------------------------
int vtkMultiProcessController::AllReduce(
const vtkBoundingBox& sendBuffer, vtkBoundingBox& recvBuffer)
{
if (this->GetNumberOfProcesses() <= 1)
{
recvBuffer = sendBuffer;
return 1;
}
double send_min[3] = { VTK_DOUBLE_MAX, VTK_DOUBLE_MAX, VTK_DOUBLE_MAX };
double send_max[3] = { VTK_DOUBLE_MIN, VTK_DOUBLE_MIN, VTK_DOUBLE_MIN };
if (sendBuffer.IsValid())
{
sendBuffer.GetMinPoint(send_min);
sendBuffer.GetMaxPoint(send_max);
}
double recv_min[3], recv_max[3];
if (this->AllReduce(send_min, recv_min, 3, vtkCommunicator::MIN_OP))
{
if (this->AllReduce(send_max, recv_max, 3, vtkCommunicator::MAX_OP))
{
recvBuffer.SetMinPoint(recv_min);
recvBuffer.SetMaxPoint(recv_max);
return 1;
}
}
return 0;
}
//============================================================================
// The intent is to give access to a processes controller from a static method.
......
......@@ -54,6 +54,7 @@
#include "vtkCommunicator.h" // Needed for direct access to communicator
class vtkBoundingBox;
class vtkCollection;
class vtkDataObject;
class vtkDataSet;
......@@ -1419,7 +1420,15 @@ public:
return this->Communicator->AllReduce(sendBuffer, recvBuffer, operation);
}
// Internally implemented RMI to break the process loop.
//@{
/**
* Convenience methods to reduce bounds.
*/
int Reduce(const vtkBoundingBox& sendBuffer, vtkBoundingBox& recvBuffer, int destProcessId);
int AllReduce(const vtkBoundingBox& sendBuffer, vtkBoundingBox& recvBuffer);
//@}
// Internally implemented RMI to break the process loop.
protected:
vtkMultiProcessController();
......
Supports Markdown
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