From 5d6db7e434758f79a1ed6f38b947dd185ba2ed8e Mon Sep 17 00:00:00 2001 From: exapde Date: Tue, 21 May 2024 22:39:27 -0400 Subject: [PATCH] allocate memory for work --- src/ML-POD/eapod.cpp | 5 +++-- src/ML-POD/fitpod_command.cpp | 11 ++--------- src/ML-POD/pair_pod.cpp | 2 +- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/ML-POD/eapod.cpp b/src/ML-POD/eapod.cpp index 2f56ccd8da..88ac797351 100644 --- a/src/ML-POD/eapod.cpp +++ b/src/ML-POD/eapod.cpp @@ -2272,6 +2272,7 @@ void EAPOD::eigenvaluedecomposition(double *Phi, double *Lambda, int N) double *S = (double *) malloc(N*ns*sizeof(double)); double *Q = (double *) malloc(N*ns*sizeof(double)); double *A = (double *) malloc(ns*ns*sizeof(double)); + double *work = (double *) malloc(ns*ns*sizeof(double)); double *b = (double *) malloc(ns*sizeof(double)); // Generate the xij array @@ -2294,7 +2295,7 @@ void EAPOD::eigenvaluedecomposition(double *Phi, double *Lambda, int N) // Compute the eigenvectors and eigenvalues of A int lwork = ns * ns; // the length of the array work, lwork >= max(1,3*N-1) int info = 1; // = 0: successful exit - double work[ns*ns]; + //double work[ns*ns]; char chv = 'V'; char chu = 'U'; DSYEV(&chv, &chu, &ns, A, &ns, b, work, &lwork, &info); @@ -2331,7 +2332,7 @@ void EAPOD::eigenvaluedecomposition(double *Phi, double *Lambda, int N) } // Free temporary arrays - free(xij); free(S); free(A); free(b); free(Q); + free(xij); free(S); free(A); free(work); free(b); free(Q); } /** diff --git a/src/ML-POD/fitpod_command.cpp b/src/ML-POD/fitpod_command.cpp index 089b55d318..bd683ecb38 100644 --- a/src/ML-POD/fitpod_command.cpp +++ b/src/ML-POD/fitpod_command.cpp @@ -1301,6 +1301,7 @@ void FitPOD::environment_cluster_calculation(const datastruct &data) double *basedescmatrix = (double *) malloc(nAtoms*Mdesc*sizeof(double)); double *pca = (double *) malloc(nAtoms*nComponents*sizeof(double)); double *A = (double *) malloc(Mdesc*Mdesc*sizeof(double)); + double *work = (double *) malloc(Mdesc*Mdesc*sizeof(double)); double *b = (double *) malloc(Mdesc*sizeof(double)); double *Lambda = (double *) malloc(Mdesc*nelements*sizeof(double)); int *clusterSizes = (int *) malloc(nClusters*nelements*sizeof(int)); @@ -1334,12 +1335,6 @@ void FitPOD::environment_cluster_calculation(const datastruct &data) nElemAtomsCount[elem] = 0; } -// //std::cout<me, nElemAtoms[0], nElemAtoms[1]); -// printf("%d %d %d\n",comm->me, nElemAtomsCount[0], nElemAtomsCount[1]); -// printf("%d %d %d %d\n",comm->me, nElemAtomsCumSum[0], nElemAtomsCumSum[1], nElemAtomsCumSum[2]); - MPI_Barrier(MPI_COMM_WORLD); // loop over each configuration in the data set @@ -1412,7 +1407,6 @@ void FitPOD::environment_cluster_calculation(const datastruct &data) // Calculate eigenvalues and eigenvectors of A int lwork = Mdesc * Mdesc; // the length of the array work, lwork >= max(1,3*N-1) int info = 1; // = 0: successful exit - double work[lwork]; DSYEV(&chv, &chu, &Mdesc, A, &Mdesc, b, work, &lwork, &info); @@ -1454,8 +1448,6 @@ void FitPOD::environment_cluster_calculation(const datastruct &data) savematrix2binfile(data.filenametag + "_pca_matrix_elem" + std::to_string(elem+1) + "_proc" + std::to_string(comm->me+1) + ".bin", pca, nComponents, nAtoms); saveintmatrix2binfile(data.filenametag + "_cluster_assignments_elem" + std::to_string(elem+1) + "_proc" + std::to_string(comm->me+1) + ".bin", assignments, nAtoms, 1); } - //savematrix2binfile(data.filenametag + "_pca_matrix_elem" + std::to_string(elem+1) + "_proc" + std::to_string(comm->me+1) + ".bin", pca, nComponents, nAtoms); - //saveintmatrix2binfile(data.filenametag + "_cluster_assignments_elem" + std::to_string(elem+1) + "_proc" + std::to_string(comm->me+1) + ".bin", assignments, nAtoms, 1); MPI_Barrier(MPI_COMM_WORLD); } @@ -1468,6 +1460,7 @@ void FitPOD::environment_cluster_calculation(const datastruct &data) free(basedescmatrix); free(pca); free(A); + free(work); free(b); free(clusterSizes); free(Lambda); diff --git a/src/ML-POD/pair_pod.cpp b/src/ML-POD/pair_pod.cpp index 9b79e82416..8833717ee7 100644 --- a/src/ML-POD/pair_pod.cpp +++ b/src/ML-POD/pair_pod.cpp @@ -981,7 +981,7 @@ void PairPOD::radialangularsum2(int Ni, int Nij) int start = numij[i]; int nj = numij[i+1]-start; - double sum[nelements]; + double sum[100]; for (int j=0; j