escript  Revision_
escriptcore/src/IndexList.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2016 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16 
17 #ifndef __ESCRIPT_INDEXLIST_H__
18 #define __ESCRIPT_INDEXLIST_H__
19 
20 #include <escript/DataTypes.h>
21 
22 // pre-reserving saves time under OpenMP. The 85 is a value taken over
23 // from revision ~101 by jgs.
24 #define ESYS_INDEXLIST_LENGTH 85
25 
26 namespace escript {
27 
28 struct IndexList {
29  IndexList() : n(0), extension(NULL) {}
30  ~IndexList() { delete extension; }
31 
35 
37  inline void insertIndex(DataTypes::index_t index)
38  {
39  for (DataTypes::dim_t i=0; i<n; i++) {
40  if (m_list[i] == index)
41  return;
42  }
43  if (n < ESYS_INDEXLIST_LENGTH) {
44  m_list[n++] = index;
45  } else {
46  if (extension == NULL)
47  extension = new IndexList();
48  extension->insertIndex(index);
49  }
50  }
51 
54  DataTypes::index_t range_max) const
55  {
56  DataTypes::dim_t out=0;
57  for (DataTypes::dim_t i=0; i < n; i++) {
58  if (m_list[i] >= range_min && range_max > m_list[i])
59  ++out;
60  }
61  if (extension)
62  out += extension->count(range_min, range_max);
63  return out;
64  }
65 
67  inline void toArray(DataTypes::index_t* array,
68  DataTypes::index_t range_min, DataTypes::index_t range_max,
69  DataTypes::index_t index_offset) const
70  {
71  DataTypes::index_t idx = 0;
72  for (DataTypes::dim_t i=0; i < n; i++) {
73  if (m_list[i] >= range_min && range_max > m_list[i]) {
74  array[idx] = m_list[i]+index_offset;
75  ++idx;
76  }
77  }
78  if (extension)
79  extension->toArray(&array[idx], range_min, range_max, index_offset);
80  }
81 };
82 
83 } // namespace escript
84 
85 #endif // __ESCRIPT_INDEXLIST_H__
86 
DataTypes::dim_t count(DataTypes::index_t range_min, DataTypes::index_t range_max) const
counts the number of row indices in the IndexList in
Definition: escriptcore/src/IndexList.h:53
Definition: AbstractContinuousDomain.cpp:22
DataTypes::index_t m_list[85]
Definition: escriptcore/src/IndexList.h:32
#define ESYS_INDEXLIST_LENGTH
Definition: escriptcore/src/IndexList.h:24
IndexList()
Definition: escriptcore/src/IndexList.h:29
~IndexList()
Definition: escriptcore/src/IndexList.h:30
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:59
void toArray(DataTypes::index_t *array, DataTypes::index_t range_min, DataTypes::index_t range_max, DataTypes::index_t index_offset) const
index list to array
Definition: escriptcore/src/IndexList.h:67
DataTypes::dim_t n
Definition: escriptcore/src/IndexList.h:33
Definition: escriptcore/src/IndexList.h:28
void insertIndex(DataTypes::index_t index)
inserts row index into the IndexList in if it does not exist
Definition: escriptcore/src/IndexList.h:37
index_t dim_t
Definition: DataTypes.h:64
IndexList * extension
Definition: escriptcore/src/IndexList.h:34