From 0d0a2f280d8f517697a942a3727e2a9630f291d1 Mon Sep 17 00:00:00 2001 From: varray Date: Wed, 8 Jan 2025 20:57:59 +0100 Subject: [PATCH] correction of void function + memory allocation for windows compilation with mex. --- mexFunctions/source/Nsum_mex.cpp | 6 +++--- mexFunctions/source/compile_mex.m | 2 ++ mexFunctions/source/proxSpMat2xNc.cpp | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/mexFunctions/source/Nsum_mex.cpp b/mexFunctions/source/Nsum_mex.cpp index 0333868..d376e8b 100644 --- a/mexFunctions/source/Nsum_mex.cpp +++ b/mexFunctions/source/Nsum_mex.cpp @@ -20,7 +20,7 @@ * to the element X[i+j*dims[0]+z*dims[0]*dims[1]] */ -double Nsum(double *X, double *V, double *idx, int n, int I, int i) +void Nsum(double *X, double *V, double *idx, int n, int I, int i) { int k; int ctr=0; @@ -35,7 +35,7 @@ double Nsum(double *X, double *V, double *idx, int n, int I, int i) } -double NsumC(double *Xr, double *Xi, double *Vr, double *Vi, double *idx, int n, int I, int i) +void NsumC(double *Xr, double *Xi, double *Vr, double *Vi, double *idx, int n, int I, int i) { int k; int ctr=0; @@ -87,7 +87,7 @@ void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) { int Nw=dims[number_of_dims-1]; int N=num_of_X/Nw; // N= N1 x N2 ... - mwSize dims_V[number_of_dims-1]; // dimensions of the output matrix V + mwSize * dims_V = (mwSize *)calloc(sizeof(mwSize), number_of_dims-1); // dimensions of the output matrix V for (j=0; j < number_of_dims-1; j++) dims_V[j]=dims[j]; diff --git a/mexFunctions/source/compile_mex.m b/mexFunctions/source/compile_mex.m index 930b24e..23eb818 100644 --- a/mexFunctions/source/compile_mex.m +++ b/mexFunctions/source/compile_mex.m @@ -2,6 +2,8 @@ if ispc mex -v proxSpMat2xNc.cpp libmwblas.lib CFLAGS="\$CFLAGS /openmp" LDFLAGS="\$LDFLAGS /openmp" -largeArrayDims -I../headers/ + mex -v Nsum_mex.cpp libmwblas.lib CFLAGS="\$CFLAGS /openmp" LDFLAGS="\$LDFLAGS /openmp" -largeArrayDims -I../headers/ else mex -v proxSpMat2xNc.c -lmwblas CFLAGS="\$CFLAGS -fopenmp -std=c99“ LDFLAGS="\$LDFLAGS -fopenmp" -largeArrayDims -I../headers/ + mex -v Nsum_mex.c -lmwblas CFLAGS="\$CFLAGS -fopenmp -std=c99“ LDFLAGS="\$LDFLAGS -fopenmp" -largeArrayDims -I../headers/ end diff --git a/mexFunctions/source/proxSpMat2xNc.cpp b/mexFunctions/source/proxSpMat2xNc.cpp index 10e40a0..cb97ca8 100644 --- a/mexFunctions/source/proxSpMat2xNc.cpp +++ b/mexFunctions/source/proxSpMat2xNc.cpp @@ -70,8 +70,8 @@ void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) { double *Xp=mxGetPr(plhs[0]); int k; - double tmp[2*nc]; - double tmp2[2*nc]; + double *tmp = (double*)calloc(sizeof(double), 2*nc); + double *tmp2= (double*)calloc(sizeof(double), 2*nc); if(p==2){ #pragma omp parallel for shared(X, Xp) private(i,k,tmp,tmp2)