Skip to content

Commit

Permalink
Remove non-standard array allocation in example code.
Browse files Browse the repository at this point in the history
  • Loading branch information
chuckyount committed Apr 25, 2024
1 parent 040b610 commit 4105e91
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
20 changes: 14 additions & 6 deletions src/examples/swe_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,12 @@ int main(int argc, char** argv) {
double t_export = 0.02;

// Some 1D buffers used to copy slices of data to/from YASK vars.
double hbuf[ysz];
double ebuf[ysz];
double ubuf[ysz];
double vbuf[ysz];
double keHbuf[ysz];
double pebuf[ysz];
auto* hbuf = new double[ysz];
auto* ebuf = new double[ysz];
auto* ubuf = new double[ysz];
auto* vbuf = new double[ysz];
auto* keHbuf = new double[ysz];
auto* pebuf = new double[ysz];

// Init whole vars to default values.
h->set_all_elements_same(1.0);
Expand Down Expand Up @@ -601,6 +601,14 @@ int main(int argc, char** argv) {
}
#endif

// Free buffers.
delete[] hbuf;
delete[] ebuf;
delete[] ubuf;
delete[] vbuf;
delete[] keHbuf;
delete[] pebuf;

// Report global error.
if (rank_num == msg_rank) {
gerr_L2 = sqrt(gerr_L2);
Expand Down
5 changes: 4 additions & 1 deletion src/examples/wave_eq_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ int main(int argc, char** argv) {
soln->get_var("depth")->set_element(h, {});

// Buffer used to copy slices of data to/from YASK var.
double ebuf[ysz];
auto* ebuf = new double[ysz];

// Init vars.
e->set_all_elements_same(0.0);
Expand Down Expand Up @@ -392,6 +392,9 @@ int main(int argc, char** argv) {
}
#endif

// Free buffer.
delete[] ebuf;

// Report global stats.
if (rank_num == msg_rank) {
oerr_L2 = sqrt(oerr_L2);
Expand Down

0 comments on commit 4105e91

Please sign in to comment.