From 8a5aa076fd28e0cfe99532f7d6bd8015822bb9cf Mon Sep 17 00:00:00 2001 From: sunwen Date: Tue, 23 May 2023 15:41:10 +0800 Subject: [PATCH] Use omp to make getGeometryInfo speed up. --- src/common/getGeometryInfo.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/common/getGeometryInfo.cpp b/src/common/getGeometryInfo.cpp index 1e0ebe7..c27b195 100644 --- a/src/common/getGeometryInfo.cpp +++ b/src/common/getGeometryInfo.cpp @@ -34,12 +34,21 @@ Matrix loadSensitivity() Matrix y0 = linspace(-90,90,fullSens1D.getDataSize()); Matrix x1 = linspace(-90,90,181); Matrix y1 = linspace(-90,90,181); - Matrix y = repmat(Matrix::copyFromRawData(y1.getData(), 1),181,1); - Matrix result = interpn(x0,y0,fullSens2D,x1,y,InterpnMethod::Linear); - for(int i=1; i<181; ++i) + //Matrix y = repmat(Matrix::copyFromRawData(y1.getData(), 1),181,1); + double* resultData = new double[y1.getDataSize() * x1.getDataSize()]; + Matrix result = Matrix::fromRawData(resultData, y1.getDataSize(), x1.getDataSize()); + std::vector resultTemp(181); + //Matrix result = interpn(x0,y0,fullSens2D,x1,y,InterpnMethod::Linear); + #pragma omp parallel for + for(int i=0; i<181; ++i) { - y = repmat(Matrix::copyFromRawData(y1.getData() + i, 1),181,1); - result = horzcat(result, interpn(x0,y0,fullSens2D,x1,y,InterpnMethod::Linear)); + Matrix y = repmat(Matrix::copyFromRawData(y1.getData() + i, 1),181,1); + resultTemp[i]=interpn(x0,y0,fullSens2D,x1,y,InterpnMethod::Linear); + } + for(int i=0; i<181; ++i) + { + std::copy(resultTemp[i].getData(), resultTemp[i].getData() + resultTemp[i].getDataSize(), resultData); + resultData += resultTemp[i].getDataSize(); } return result; }