File: TestGenerateProcessIds.cxx

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 205,992 kB
  • sloc: cpp: 2,336,570; ansic: 327,116; python: 111,200; yacc: 4,104; java: 3,977; sh: 3,032; xml: 2,771; perl: 2,189; lex: 1,787; makefile: 185; javascript: 165; objc: 153; tcl: 59
file content (74 lines) | stat: -rw-r--r-- 2,586 bytes parent folder | download | duplicates (3)
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
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause

// Tests vtkGenerateProcessIds and the new ProcessIds dataset attribute.

#include "vtkCellData.h"
#include "vtkDataSet.h"
#include "vtkGenerateProcessIds.h"
#include "vtkIdTypeArray.h"
#include "vtkMPIController.h"
#include "vtkNew.h"
#include "vtkPointData.h"
#include "vtkRTAnalyticSource.h"

static int TestGenerator(vtkDataSetAttributes* dataSetAttributes, int rank);

int TestGenerateProcessIds(int argc, char* argv[])
{
  // Note that this will create a vtkMPIController if MPI
  // is configured, vtkThreadedController otherwise.
  vtkNew<vtkMPIController> controller;
  controller->Initialize(&argc, &argv, 0);
  vtkMultiProcessController::SetGlobalController(controller);

  // Create and execute pipeline
  vtkNew<vtkRTAnalyticSource> wavelet;
  vtkNew<vtkGenerateProcessIds> pidGenerator;
  pidGenerator->SetInputConnection(wavelet->GetOutputPort());
  pidGenerator->GenerateCellDataOn();
  pidGenerator->Update();

  vtkDataSet* pidOutput = vtkDataSet::SafeDownCast(pidGenerator->GetOutput());
  int myRank = controller->GetLocalProcessId();

  int retVal = TestGenerator(pidOutput->GetPointData(), myRank);
  retVal =
    (TestGenerator(pidOutput->GetCellData(), myRank) == EXIT_FAILURE) ? EXIT_FAILURE : retVal;

  controller->Finalize();
  return retVal;
}

int TestGenerator(vtkDataSetAttributes* dataSetAttributes, int rank)
{
  vtkDataArray* pidDataArray = dataSetAttributes->GetProcessIds();
  vtkIdType nbTuples = dataSetAttributes->GetNumberOfTuples();

  if (!pidDataArray)
  {
    vtkGenericWarningMacro("ProcessIds attribute from " << dataSetAttributes->GetClassName()
                                                        << " should not be nullptr");
    return EXIT_FAILURE;
  }
  vtkIdType pidArraySize = pidDataArray->GetDataSize();
  if (pidArraySize != nbTuples)
  {
    vtkGenericWarningMacro(<< "Wrong size for ProcessIds attribute from "
                           << dataSetAttributes->GetClassName() << ". Should be: " << nbTuples
                           << " but is: " << pidArraySize);
    return EXIT_FAILURE;
  }
  for (vtkIdType i = 0; i < nbTuples; ++i)
  {
    if (pidDataArray->GetTuple1(i) != rank)
    {
      vtkGenericWarningMacro(<< "Wrong id in ProcessIds attribute from "
                             << dataSetAttributes->GetClassName() << ". Should be: " << rank
                             << " but is: " << pidDataArray->GetTuple1(i));
      return EXIT_FAILURE;
    }
  }

  return EXIT_SUCCESS;
}