1 //============================================================================
2 //  Copyright (c) Kitware, Inc.
3 //  All rights reserved.
4 //  See LICENSE.txt for details.
5 //
6 //  This software is distributed WITHOUT ANY WARRANTY; without even
7 //  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 //  PURPOSE.  See the above copyright notice for more information.
9 //============================================================================
10 
11 #include <vtkm/cont/serial/internal/DeviceAdapterAlgorithmSerial.h>
12 
13 namespace vtkm
14 {
15 namespace cont
16 {
17 
ScheduleTask(vtkm::exec::serial::internal::TaskTiling1D & functor,vtkm::Id size)18 void DeviceAdapterAlgorithm<vtkm::cont::DeviceAdapterTagSerial>::ScheduleTask(
19   vtkm::exec::serial::internal::TaskTiling1D& functor,
20   vtkm::Id size)
21 {
22   VTKM_LOG_SCOPE_FUNCTION(vtkm::cont::LogLevel::Perf);
23 
24   const vtkm::Id MESSAGE_SIZE = 1024;
25   char errorString[MESSAGE_SIZE];
26   errorString[0] = '\0';
27   vtkm::exec::internal::ErrorMessageBuffer errorMessage(errorString, MESSAGE_SIZE);
28   functor.SetErrorMessageBuffer(errorMessage);
29 
30   const vtkm::Id iterations = size / 1024;
31   vtkm::Id index = 0;
32   for (vtkm::Id i = 0; i < iterations; ++i)
33   {
34     functor(index, index + 1024);
35     index += 1024;
36   }
37   functor(index, size);
38 
39   if (errorMessage.IsErrorRaised())
40   {
41     throw vtkm::cont::ErrorExecution(errorString);
42   }
43 }
44 
ScheduleTask(vtkm::exec::serial::internal::TaskTiling3D & functor,vtkm::Id3 size)45 void DeviceAdapterAlgorithm<vtkm::cont::DeviceAdapterTagSerial>::ScheduleTask(
46   vtkm::exec::serial::internal::TaskTiling3D& functor,
47   vtkm::Id3 size)
48 {
49   VTKM_LOG_SCOPE_FUNCTION(vtkm::cont::LogLevel::Perf);
50 
51   const vtkm::Id MESSAGE_SIZE = 1024;
52   char errorString[MESSAGE_SIZE];
53   errorString[0] = '\0';
54   vtkm::exec::internal::ErrorMessageBuffer errorMessage(errorString, MESSAGE_SIZE);
55   functor.SetErrorMessageBuffer(errorMessage);
56 
57   for (vtkm::Id k = 0; k < size[2]; ++k)
58   {
59     for (vtkm::Id j = 0; j < size[1]; ++j)
60     {
61       functor(size, 0, size[0], j, k);
62     }
63   }
64 
65   if (errorMessage.IsErrorRaised())
66   {
67     throw vtkm::cont::ErrorExecution(errorString);
68   }
69 }
70 }
71 }
72