File: TaskParallelismWithPorts.cxx

package info (click to toggle)
vtk9 9.5.2%2Bdfsg2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 203,992 kB
  • sloc: cpp: 2,308,867; ansic: 326,445; python: 111,200; yacc: 4,104; java: 3,977; sh: 3,003; xml: 2,771; perl: 2,189; lex: 1,787; javascript: 165; objc: 153; makefile: 145; tcl: 59
file content (70 lines) | stat: -rw-r--r-- 2,158 bytes parent folder | download | duplicates (5)
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
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
// This example demonstrates how to write a task parallel application
// with VTK. It creates two different pipelines and assigns each to
// one processor. These pipelines are:
// 1. rtSource -> contour            -> probe               .-> append
//             \                     /                  port
//              -> gradient magnitude                  /
// 2. rtSource -> gradient -> shrink -> glyph3D -> port
// See task3.cxx and task4.cxx for the pipelines.

#include "TaskParallelismWithPorts.h"

// This function sets up properties common to both processes
// and executes the task corresponding to the current process
void process(vtkMultiProcessController* controller, void* vtkNotUsed(arg))
{
  taskFunction task;
  int myId = controller->GetLocalProcessId();

  // Chose the appropriate task (see task3.cxx and task4.cxx)
  if (myId == 0)
  {
    task = task3;
  }
  else
  {
    task = task4;
  }

  // Run the tasks (see task3.cxx and task4.cxx)
  (*task)(EXTENT);
}

int main(int argc, char* argv[])
{

  // Note that this will create a vtkMPIController if MPI
  // is configured, vtkThreadedController otherwise.
  vtkMultiProcessController* controller = vtkMultiProcessController::New();
  controller->Initialize(&argc, &argv);

  // 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);
  }
  int numProcs = controller->GetNumberOfProcesses();

  if (numProcs != 2)
  {
    cerr << "This example requires two processes." << endl;
    controller->Finalize();
    controller->Delete();
    return 1;
  }

  // Execute the function named "process" on both processes
  controller->SetSingleMethod(process, 0);
  controller->SingleMethodExecute();

  // Clean-up and exit
  controller->Finalize();
  controller->Delete();

  return 0;
}