Skip to content

Commit 60bb4cc

Browse files
authored
Removed return codes and other cleanup for Field and Dimension
Continued cleanup of omega focused on Field and Dimension, including: - removing return codes in favor of abort for most routines - use of Error code and Error infrastructure where needed - updated docs - cleanup of unit tests to reduce output
2 parents e73ce82 + b00e936 commit 60bb4cc

26 files changed

+554
-1037
lines changed

components/omega/doc/devGuide/Field.md

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Omega includes a Field class that registers available fields and associated
66
metadata for use in IO (or any other part of Omega that may require the field
77
metadata). The module owning the field will define the Field together
88
with some required metadata for compliance with the Climate and Forecast
9-
[(CF) metadata conventios.](http://cfconventions.org/). Groups of Fields
9+
[(CF) metadata conventions.](http://cfconventions.org/). Groups of Fields
1010
can also be defined to provide a short cut to groups that are commonly used
1111
together, like the model state and tracer groups. Two special Fields, CodeMeta
1212
and SimMeta (with default names "code" and "simulation", respectively), are
@@ -20,7 +20,7 @@ To use the Field class, the Field header file must be included and as part of
2020
the application initialization, there should be a call to the init method:
2121
Fields initialized with the init method:
2222
```c++
23-
int Err = Field::init();
23+
Field::init();
2424
```
2525
which primarily defines the CodeMeta and SimMeta fields for later use.
2626
For array fields, the appropriate Dimensions must be defined. The default
@@ -79,15 +79,14 @@ purpose.
7979

8080
Additional metadata in the form of a name-value pair can be added using:
8181
```c++
82-
int Err = MyField->addMetadata(
83-
MetaName, // [in] Name of new metadata (string)
84-
Value // [in] Value of new metadata
82+
MyField->addMetadata(MetaName, // [in] Name of new metadata (string)
83+
Value // [in] Value of new metadata
8584
);
8685
```
8786
where Value can be any supported data type (I4, I8, R4, R8, bool, string).
8887
Multiple pairs can be added in a single call using:
8988
``` c++
90-
Err = SimField->addMetadata(
89+
SimField->addMetadata(
9190
{std::make_pair("Name1", Val1),
9291
std::make_pair("Name2", Val2),
9392
std::make_pair("Name3", Val3),
@@ -100,16 +99,16 @@ As mentioned above, the actual data array is attached in a separate call
10099
using a templated form. If the pointer to the Field is available, use the
101100
member function:
102101
```c++
103-
int Err = MyField->attachData<ArrayType>(InDataArray);
102+
MyField->attachData<ArrayType>(InDataArray);
104103
// for example:
105-
int Err = MyField->attachData<HostArray1DI4>(CellID);
106-
int Err = MyField->attachData<Array2DR8>(NormalVelocity);
104+
MyField->attachData<HostArray1DI4>(CellID);
105+
MyField->attachData<Array2DR8>(NormalVelocity);
107106
```
108107
where ArrayType is one of the supported array types (Array1DI4, etc. or
109108
HostArray1DI4, etc.). If the Field pointer has not been retrieved, an interface
110109
is provided using the field name:
111110
```c++
112-
int Err = Field::attachFieldData<ArrayType>(
111+
Field::attachFieldData<ArrayType>(
113112
FieldName, // [in] Name of Field (string)
114113
InDataArray // [in] Array with data to attach
115114
);
@@ -170,7 +169,7 @@ The dimension information can be retrieved using:
170169
```c++
171170
int NDims = MyField->getNumDims();
172171
std::vector<std::string> MyDimNames(NDims);
173-
int Err = MyField->getDimNames(MyDimNames);
172+
MyField->getDimNames(MyDimNames);
174173
```
175174
Once the dimension names have been retrieved, the Dimension class API can be
176175
used to extract further dimension information. Two other field quantities
@@ -191,13 +190,13 @@ functions. To retrieve a pointer to the full Field, use:
191190
With this pointer all the member functions above can be used.
192191
The Metadata associated with a field can be retrieved individually using:
193192
```c++
194-
int Err = MyField->getMetadata(MetadataName, MetaValue);
193+
Error Err = MyField->getMetadata(MetadataName, MetaValue);
195194
```
196195
where the MetaValue can be a scalar of any supported data type (I4, I8, R4, R8,
197196
bool, std::string). If the value of a metadata entry needs to be changed,
198197
an update function is provided:
199198
```c++
200-
int Err = MyField->updateMetadata(MetadataName, NewMetaValue);
199+
MyField->updateMetadata(MetadataName, NewMetaValue);
201200
```
202201
The existence of a metadata entry can be determined with:
203202
```c++
@@ -229,13 +228,13 @@ location as described previously.
229228

230229
Metadata can be removed from a Field using:
231230
```c++
232-
int Err = MyField->removeMetadata(MetaName);
231+
MyField->removeMetadata(MetaName);
233232
MyField->removeAllMetadata();
234233
```
235234
depending on whether a single metadata entry or all metadata entries need to
236235
be deleted. Entire fields can be removed using:
237236
```c++
238-
int Err = Field::destroy(FieldName);
237+
Field::destroy(FieldName);
239238
```
240239
and before exiting, all fields should be removed using:
241240
```c++
@@ -253,8 +252,8 @@ is created by first creating an empty group with the desired name:
253252
Fields can then be added either through a member function if the group
254253
pointer is available, or by group name:
255254
```c++
256-
int Err = MyGroup->addField(FieldName);
257-
int Err = FieldGroup::addFieldToGroup(FieldName, GroupName);
255+
MyGroup->addField(FieldName);
256+
FieldGroup::addFieldToGroup(FieldName, GroupName);
258257
```
259258
The latter is useful especially if the group was created elsewhere. If the
260259
field has already been added to the group, no additional entries are created.
@@ -289,15 +288,15 @@ The FieldGroup pointer can also be retrieved:
289288

290289
A field can be removed from a field group using:
291290
```c++
292-
int Err = FieldGroup::removeField(FieldName);
291+
MyGroup->removeField(FieldName);
293292
// or
294-
int Err = removeFieldFromGroup(FieldName, GroupName);
293+
FieldGroup::removeFieldFromGroup(FieldName, GroupName);
295294
```
296295
The removal of a field from a group does not remove the field itself, it only
297296
removes the field name from the list of fields assigned to the group.
298297
The entire group can be removed with:
299298
```c++
300-
int Err = FieldGroup::destroy(GroupName);
299+
FieldGroup::destroy(GroupName);
301300
```
302301
and the usual ``FieldGroup::clear();`` should be used to remove all field
303302
groups before exiting.

components/omega/src/base/Decomp.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,7 @@ Decomp::Decomp(
450450
const std::string &MeshFileName_ //< [in] name of file with mesh info
451451
) {
452452

453-
Error IOErr;
454453
bool TimerFlag = Pacer::start("Decomp construct");
455-
int Err = 0; // internal error code
456454

457455
// Retrieve some info on the MPI layout
458456
MPI_Comm Comm = InEnv->getComm();
@@ -1123,8 +1121,6 @@ void Decomp::partCellsParMetisKWay(
11231121
const std::vector<I4> &CellsOnCellInit // [in] cell nbrs in linear distrb
11241122
) {
11251123

1126-
int Err = 0; // internal error code for MPI and Metis/ParMetis
1127-
11281124
// Retrieve some info on the MPI layout
11291125
MPI_Comm Comm = InEnv->getComm();
11301126
I4 NumTasks = InEnv->getNumTasks();
@@ -1533,6 +1529,8 @@ void Decomp::partEdges(
15331529
// Broadcast this buffer
15341530
Err = Broadcast(EdgeBuf, InEnv, ITask);
15351531
TimerFlag = Pacer::stop("partEdgesOwnerBcast") && TimerFlag;
1532+
if (Err != 0)
1533+
ABORT_ERROR("Decomp partEdges: Error broadcasting Edge owner info");
15361534

15371535
// For each edge in the buffer, check to see if the task owns
15381536
// the cell. If so, add the edge ID to the owned edges list.
@@ -1666,6 +1664,8 @@ void Decomp::partEdges(
16661664
// Broadcast the list of edges owned by this task
16671665
Err = Broadcast(EdgeBuf, InEnv, ITask);
16681666
TimerFlag = Pacer::stop("partEdgesFinalBcast") && TimerFlag;
1667+
if (Err != 0)
1668+
ABORT_ERROR("Decomp partEdges: Error in final broadcast");
16691669

16701670
// Extract the buffer into a local search vector
16711671
TimerFlag = Pacer::start("partEdgesFinalSearch") && TimerFlag;
@@ -1801,6 +1801,8 @@ void Decomp::partVertices(
18011801
// Broadcast this buffer
18021802
Err = Broadcast(VrtxBuf, InEnv, ITask);
18031803
TimerFlag = Pacer::stop("partVerticesOwnedBcast") && TimerFlag;
1804+
if (Err != 0)
1805+
ABORT_ERROR("Decomp partVertices: error broadcasting owned vertices");
18041806

18051807
// For each vertex in the buffer, check to see if the task owns
18061808
// the cell. If so, add the vertex ID to the owned vertices list.
@@ -1935,6 +1937,8 @@ void Decomp::partVertices(
19351937
// Broadcast the list of vertices owned by this task
19361938
Err = Broadcast(VrtxBuf, InEnv, ITask);
19371939
TimerFlag = Pacer::stop("partVerticesFinalBcast") && TimerFlag;
1940+
if (Err != 0)
1941+
ABORT_ERROR("Decomp partVertices: error in final broadcast");
19381942

19391943
// Extract the buffer into a local search vector
19401944
TimerFlag = Pacer::start("partVerticesFinalSearch") && TimerFlag;

components/omega/src/infra/Dimension.cpp

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//===-- infra/Dimension.cpp - OMEGA dimension implementation -----*- C++
2-
//-*-===//
1+
//===-- infra/Dimension.cpp - OMEGA dimension implementation ----*- C++ -*-===//
32
//
43
// Implementation of the field dimension class used by the multi-dimensional
54
// Field class
@@ -48,13 +47,13 @@ std::shared_ptr<Dimension> Dimension::create(
4847
// Retrieve the previously defined dim and use that unless...
4948
Dim = get(Name);
5049

51-
// The already-defined dim has different properties, so the dimensions
52-
// are not the same and we have a conflict
50+
// If the already-defined dim has different properties, the dimensions
51+
// are not the same and we have a conflict and should abort
5352
if ((Dim->GlobalLength != GlobalLength) or
5453
(Dim->LocalLength != LocalLength) or !Dim->Distributed) {
55-
LOG_ERROR("Attempt to create dimension {} but a dimension with"
56-
" that name already exists with different properties",
57-
Name);
54+
ABORT_ERROR("Attempt to create dimension {} but a dimension with"
55+
" that name already exists with different properties",
56+
Name);
5857
Dim = nullptr;
5958
}
6059

@@ -85,13 +84,13 @@ Dimension::create(const std::string &Name, // [in] name of dimension
8584
// Retrieve the previously defined dim and use that unless...
8685
Dim = get(Name);
8786

88-
// The already-defined dim has different properties, so the dimensions
89-
// are not the same and we have a conflict
87+
// If the already-defined dim has different properties, the dimensions
88+
// are not the same and we have a conflict and must abort
9089
if ((Dim->GlobalLength != GlobalLength) or
9190
(Dim->LocalLength != GlobalLength) or Dim->Distributed) {
92-
LOG_ERROR("Attempt to create dimension {} but a dimension with"
93-
" that name already exists with different properties",
94-
Name);
91+
ABORT_ERROR("Attempt to create dimension {} but a dimension with"
92+
" that name already exists with different properties",
93+
Name);
9594
Dim = nullptr;
9695
}
9796

@@ -130,9 +129,8 @@ void Dimension::destroy(
130129
if (exists(Name)) {
131130
AllDims.erase(Name);
132131
} else {
133-
LOG_ERROR("Attempt to destroy the dimension {} failed: "
134-
"dimension does not exist or has not been defined.",
135-
Name);
132+
LOG_WARN("Ignoring attempt to destroy the non-existent dimension {}.",
133+
Name);
136134
}
137135

138136
} // end destroy
@@ -146,14 +144,11 @@ void Dimension::clear() { AllDims.clear(); }
146144
std::shared_ptr<Dimension>
147145
Dimension::get(const std::string &Name // [in] Name of dimension
148146
) {
149-
if (exists(Name)) {
150-
return AllDims[Name];
151-
} else {
152-
LOG_ERROR("Cannot retrieve dimension {}: dimension does not exist"
153-
" or has not net been defined",
154-
Name);
155-
return nullptr;
156-
}
147+
if (!exists(Name))
148+
ABORT_ERROR("Cannot retrieve dimension {}: dimension does not exist.",
149+
Name);
150+
151+
return AllDims[Name];
157152

158153
} // end get full dimension instance
159154

@@ -176,9 +171,9 @@ bool Dimension::isDistributedDim(
176171
return ThisDim->Distributed;
177172

178173
} else {
179-
LOG_ERROR("Cannot check distribution of dimension {}: "
180-
"dimension does not exist or has not been defined",
181-
Name);
174+
LOG_WARN("Cannot check distribution of dimension {}: "
175+
"dimension does not exist or has not been defined",
176+
Name);
182177
return false;
183178
}
184179
}
@@ -192,18 +187,16 @@ I4 Dimension::getLengthGlobal() const { return GlobalLength; }
192187
I4 Dimension::getDimLengthGlobal(
193188
const std::string &Name // [in] name of dimension
194189
) {
195-
I4 Length;
190+
I4 Length = -1;
196191

197-
// Make sure dimension exists
192+
// If dimension exists, return global length. Otherwise abort.
198193
if (exists(Name)) {
199194
std::shared_ptr<Dimension> ThisDim = AllDims[Name];
200195
Length = ThisDim->GlobalLength;
201196

202197
} else {
203-
LOG_ERROR("Cannot get global length of dimension {}: "
204-
"dimension does not exist or has not been defined",
205-
Name);
206-
Length = -1;
198+
ABORT_ERROR("Cannot get global length of non-existent dimension {}.",
199+
Name);
207200
}
208201

209202
return Length;
@@ -219,18 +212,16 @@ I4 Dimension::getLengthLocal() const { return LocalLength; }
219212
I4 Dimension::getDimLengthLocal(
220213
const std::string &Name // [in] name of dimension
221214
) {
222-
I4 Length;
215+
I4 Length = -1;
223216

224-
// Make sure dimension exists
217+
// If dimension exists, return local length. Otherwise, abort.
225218
if (exists(Name)) {
226219
std::shared_ptr<Dimension> ThisDim = AllDims[Name];
227220
Length = ThisDim->LocalLength;
228221

229222
} else {
230-
LOG_ERROR("Cannot get local length of dimension {}: "
231-
"dimension does not exist or has not been defined",
232-
Name);
233-
Length = -1;
223+
ABORT_ERROR("Cannot get local length of non-existent dimension {}.",
224+
Name);
234225
}
235226

236227
return Length;
@@ -249,8 +240,7 @@ Dimension::getDimOffset(const std::string &Name // [in] name of dimension
249240

250241
// Abort if the dimension does not exist
251242
if (!exists(Name))
252-
ABORT_ERROR("Cannot get offset array for dimension {}: "
253-
"dimension does not exist or has not been defined",
243+
ABORT_ERROR("Cannot get offset array for non-existent dimension {}.",
254244
Name);
255245

256246
// Retrieve offset

0 commit comments

Comments
 (0)