escript Revision_
escriptcore/src/IndexList.h
Go to the documentation of this file.
1
2/*****************************************************************************
3*
4* Copyright (c) 2003-2020 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-2017 by Centre for Geoscience Computing (GeoComp)
14* Development from 2019 by School of Earth and Environmental Sciences
15**
16*****************************************************************************/
17
18#ifndef __ESCRIPT_INDEXLIST_H__
19#define __ESCRIPT_INDEXLIST_H__
20
21#include <escript/DataTypes.h>
22
23// pre-reserving saves time under OpenMP. The 85 is a value taken over
24// from revision ~101 by jgs.
25#define ESYS_INDEXLIST_LENGTH 85
26
27namespace escript {
28
29struct IndexList {
30 IndexList() : n(0), extension(NULL) {}
31 ~IndexList() { delete extension; }
32
36
39 {
40 for (DataTypes::dim_t i=0; i<n; i++) {
41 if (m_list[i] == index)
42 return;
43 }
45 m_list[n++] = index;
46 } else {
47 if (extension == NULL)
48 extension = new IndexList();
49 extension->insertIndex(index);
50 }
51 }
52
55 DataTypes::index_t range_max) const
56 {
57 DataTypes::dim_t out=0;
58 for (DataTypes::dim_t i=0; i < n; i++) {
59 if (m_list[i] >= range_min && range_max > m_list[i])
60 ++out;
61 }
62 if (extension)
63 out += extension->count(range_min, range_max);
64 return out;
65 }
66
68 inline void toArray(DataTypes::index_t* array,
69 DataTypes::index_t range_min, DataTypes::index_t range_max,
70 DataTypes::index_t index_offset) const
71 {
72 DataTypes::index_t idx = 0;
73 for (DataTypes::dim_t i=0; i < n; i++) {
74 if (m_list[i] >= range_min && range_max > m_list[i]) {
75 array[idx] = m_list[i]+index_offset;
76 ++idx;
77 }
78 }
79 if (extension)
80 extension->toArray(&array[idx], range_min, range_max, index_offset);
81 }
82};
83
84} // namespace escript
85
86#endif // __ESCRIPT_INDEXLIST_H__
87
#define ESYS_INDEXLIST_LENGTH
Definition escriptcore/src/IndexList.h:25
index_t dim_t
Definition DataTypes.h:66
int index_t
type for array/matrix indices used both globally and on each rank
Definition DataTypes.h:61
Definition AbstractContinuousDomain.cpp:23
Definition escriptcore/src/IndexList.h:29
~IndexList()
Definition escriptcore/src/IndexList.h:31
DataTypes::index_t m_list[85]
Definition escriptcore/src/IndexList.h:33
IndexList()
Definition escriptcore/src/IndexList.h:30
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:68
DataTypes::dim_t n
Definition escriptcore/src/IndexList.h:34
void insertIndex(DataTypes::index_t index)
inserts row index into the IndexList in if it does not exist
Definition escriptcore/src/IndexList.h:38
IndexList * extension
Definition escriptcore/src/IndexList.h:35
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:54