Skip to content

Commit 4f8a6a0

Browse files
committed
stdpar Tutorial: Change the daxpy mdspan example to use a non-1 length for the second dimension.
1 parent 67165c4 commit 4f8a6a0

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

stdpar-tutorial/notebooks/cpp/lab1_daxpy/exercise8.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ void initialize(std::vector<double> &x, std::vector<double> &y) {
4444
/// 2D DAXPY: AX + Y: parallel algorithm version
4545
void daxpy(double a, std::vector<double> &x, std::vector<double> &y, int ncols = 1) {
4646
assert(x.size() == y.size());
47-
if (x.size() % ncols != 0) {
48-
std::cerr << "ERROR: size " << x.size() << " not divisible by " << ncols << std::endl;
49-
std::abort();
47+
if (x.size() % ncols != 0) {
48+
std::cerr << "ERROR: size " << x.size() << " not divisible by " << ncols << std::endl;
49+
std::abort();
5050
}
5151
int nrows = x.size() / ncols;
5252

@@ -79,13 +79,15 @@ int main(int argc, char *argv[]) {
7979
// Read length of vector elements
8080
long long n = std::stoll(argv[1]);
8181

82+
long long ncols = 10;
83+
8284
// Allocate the vector
8385
std::vector<double> x(n, 0.), y(n, 0.);
8486
double a = 2.0;
8587

8688
initialize(x, y);
8789

88-
daxpy(a, x, y);
90+
daxpy(a, x, y, ncols);
8991

9092
if (!check(a, y)) {
9193
std::cerr << "ERROR!" << std::endl;

stdpar-tutorial/notebooks/cpp/lab1_daxpy/solutions/exercise8.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ void initialize(std::vector<double> &x, std::vector<double> &y) {
4444
/// 2D DAXPY: AX + Y: parallel algorithm version
4545
void daxpy(double a, std::vector<double> &x, std::vector<double> &y, int ncols = 1) {
4646
assert(x.size() == y.size());
47-
if (x.size() % ncols != 0) {
48-
std::cerr << "ERROR: size " << x.size() << " not divisible by " << ncols << std::endl;
49-
std::abort();
47+
if (x.size() % ncols != 0) {
48+
std::cerr << "ERROR: size " << x.size() << " not divisible by " << ncols << std::endl;
49+
std::abort();
5050
}
5151
int nrows = x.size() / ncols;
5252

@@ -79,13 +79,15 @@ int main(int argc, char *argv[]) {
7979
// Read length of vector elements
8080
long long n = std::stoll(argv[1]);
8181

82+
long long ncols = 10;
83+
8284
// Allocate the vector
8385
std::vector<double> x(n, 0.), y(n, 0.);
8486
double a = 2.0;
8587

8688
initialize(x, y);
8789

88-
daxpy(a, x, y);
90+
daxpy(a, x, y, 10);
8991

9092
if (!check(a, y)) {
9193
std::cerr << "ERROR!" << std::endl;

0 commit comments

Comments
 (0)