The other function is like this:
void TimeTreeMPI(vtkMultiProcessController* controller, void* arg)
{
ParallelIsoArgs_tmp* args = reinterpret_cast<ParallelIsoArgs_tmp*>(arg);
vtkNew<vtkTimerLog> timer; timer->StartTimer();
// Obtain the id of the running process and the total
// number of processes
vtkSmartPointer<vtkPolyData> polydata_mpi= args->Polydata_mpi;
double p1[3]; double p2[3]; Tree_Optimization::RandomLineThroughVolume(polydata_mpi, p1, p2, args->Rng_mpi);
double t; double x[3]; double pcoords[3]; int subId; double tol = 1.0e-8;
//RAY INTERSECTION
switch (args->ChosenLocator_mpi) {
case CELL_LOCATOR: args->CellLocator_mpi->IntersectWithLine(p1, p2, .001, t, x, pcoords, subId); break;
case CELL_TREE_LOCATOR: args->CellTreeLocator_mpi->IntersectWithLine(p1, p2, .001, t, x, pcoords, subId);break;
case STATIC_CELL_LOCATOR: args->StaticCellLocator_mpi->IntersectWithLine(p1, p2, .001, t, x, pcoords, subId);break;
case OBB_TREE: args->OBBTree_mpi->IntersectWithLine(p1, p2, .001, t, x, pcoords, subId);break;
case MODIFIED_BSP_TREE: args->ModifiedBPSTree_mpi->IntersectWithLine(p1, p2, .001, t, x, pcoords, subId);break;default:std::cout << "Unknown Locator Type!" << std::endl;}
timer->StopTimer();
// std::cout << "timer: " << timer->GetElapsedTime()<< " seconds" << std::endl;
double elapsedTime = timer->GetElapsedTime();
//GATHER AND PROCESS
vtkMPICommunicator* communicator = vtkMPICommunicator::SafeDownCast(args->Controller->GetCommunicator());
int myRank = communicator->GetLocalProcessId();
if (myRank != 0) {communicator->Send(&elapsedTime, 1, 0, 123); } // Tag 123 is arbitrary
else{
std::vector<double> receivedTimes(args->Controller->GetNumberOfProcesses());
receivedTimes[0] = elapsedTime; // Root's own elapsed time
for (int i = 1; i < args->Controller->GetNumberOfProcesses(); ++i) {
communicator->Receive(&receivedTimes[i], 1, i, 123); // Tag 123 is arbitrary
}}
// Prepare the receive buffer only on the root process
/*
if (myid == 0) {
std::vector<double> receiveBuffer;
receiveBuffer.resize(numberOfTrials * numProcesses);
// Gather doubles to the root process
controller->Gather(arg->sendBuffer.data(), receiveBuffer.data(), arg->NumberOfTrials, 0);
allTimes = 0;
vtkMPIController* control = arg.Controller;
int numProcesses = control->GetNumberOfProcesses();
for (int i = 0; i < numProcesses; ++i) {allTimes =allTimes + receiveBuffer[i];}}
*/
}//