Skip to content

Commit

Permalink
Construct distributed R only when requested.
Browse files Browse the repository at this point in the history
  • Loading branch information
dylan-copeland committed May 18, 2024
1 parent 128b83b commit bf44525
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/linalg/Matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1179,19 +1179,19 @@ void Matrix::qr_factorize(bool computeR,
qr_init(&QRmgr, &slpk);
lqfactorize(&QRmgr);

// Obtain L from the distributed overwritten matrix QRmgr.A
Matrix* L_dist_matrix = new Matrix(row_offset[myid + 1] - row_offset[myid],
ncols, distributed());

for (int rank = 0; rank < d_num_procs; ++rank) {
gather_block(&L_dist_matrix->item(0, 0), QRmgr.A, 1,
row_offset[rank] + 1, ncols,
row_offset[rank + 1] - row_offset[rank], rank);
}

Matrix *R_matrix = nullptr;
if (computeR)
{
// Obtain L from the distributed overwritten matrix QRmgr.A
Matrix* L_dist_matrix = new Matrix(row_offset[myid + 1] - row_offset[myid],
ncols, distributed());

for (int rank = 0; rank < d_num_procs; ++rank) {
gather_block(&L_dist_matrix->item(0, 0), QRmgr.A, 1,
row_offset[rank] + 1, ncols,
row_offset[rank + 1] - row_offset[rank], rank);
}

R_matrix = new Matrix(ncols, ncols, false);
if (myid == 0)
{
Expand Down Expand Up @@ -1232,6 +1232,8 @@ void Matrix::qr_factorize(bool computeR,
else
localRowsR.resize(1); // Just to have a valid pointer from data() call.

delete L_dist_matrix;

std::vector<double> recvRowsR;
if (myid == 0)
recvRowsR.resize((ncols - numLocalRowsR) * ncols);
Expand Down Expand Up @@ -1293,8 +1295,6 @@ void Matrix::qr_factorize(bool computeR,
free(QRmgr.tau);
free(QRmgr.ipiv);

delete L_dist_matrix;

QR.resize(2);
QR[0] = qr_factorized_matrix;
QR[1] = R_matrix;
Expand Down

0 comments on commit bf44525

Please sign in to comment.