From: Peter Schaefer Date: Wed, 27 Mar 2013 11:27:09 +0000 (+0100) Subject: [src]Zeitmessung + plotten X-Git-Url: https://git.leopard-lacewing.eu/?a=commitdiff_plain;h=52fb06f80a50608c4aac7f3933f8cb3119cf2c3a;p=bacc.git [src]Zeitmessung + plotten [src]mex Profiler hinzugefügt [src]kleine Laufzeit optimierungen --- diff --git a/src/A_plots.m b/src/A_plots.m index 84a2918..5428519 100644 --- a/src/A_plots.m +++ b/src/A_plots.m @@ -10,9 +10,10 @@ leg0 = {}; leg1 = {}; leg2 = {}; leg3 = {}; +leg4 = {}; sym = {}; -rows = 12; +rows = 13; for i = 1:length(files) @@ -76,6 +77,9 @@ for i = 1:length(files) leg3 = {leg3{:}... ['cond(A_{h/2}) ' l0 l1{i}]... }'; + leg4 = {leg4{:}... + ['Zeit ' l0 l1{i}]... + }'; sym = {sym{:} type2sym{data(1,[2+(i-1)*rows])}}'; end @@ -232,5 +236,28 @@ legend({leg3{:} ... print('-r600','-depsc',[printt '_cond.eps']) +%% Plotte Zeit +figure(8) +i=0; +loglog(repmat(X(:,i+1),1,1),[... + G_D(:,2+11+rows*i)... + ],type2sym{i+1}); +hold on +for i = 1:step-1 +loglog(repmat(X(:,i+1),1,1),[... + G_D(:,2+11+rows*i)... + ],type2sym{i+1}); +end +% loglog(X(:,1),[7*X(:,1).^(-1/2),3*X(:,1).^(-1/4),2*X(:,1).^(-3/4)],'-.') +hold off + +title(['Benoetigte Zeit ' t0]) +xlabel('Elemente'); +ylabel('Sekunden'); +legend({leg4{:} ... +% 'N^{-1/2}' 'N^{-1/4}' 'N^{-3/4}'... + } ,'location','northwest','box', 'off'); + +print('-r600','-depsc',[printt '_time.eps']) end \ No newline at end of file diff --git a/src/compute.m b/src/compute.m index 7cbab1f..730d896 100644 --- a/src/compute.m +++ b/src/compute.m @@ -68,6 +68,7 @@ for j = 1:times %Alle MatrixBrechenungsArten mit dem selben Netz berechnen for i = 1:length(typ) + start_time = toc; disp([num2str(size(elements,1)) ' : ' t2str(toc) ' ->' num2str(i)]) %Matrix aufbauen -> MEX V_fine = mex_build_V(coo_fine,ele_fine,zeta{i},typ(i)); @@ -100,9 +101,16 @@ for j = 1:times tmu = hmin.* b .* ... sum((x_fine(f2s)'-repmat(sum(x_fine(f2s)',1)/4,4,1)).^2)' /4; + % Export für Valgrind +% z = zeta{i}; +% t = typ(i); +% save('input.mat','coordinates','elements','z','t'); + + %Fehlerschaetzer 2 aufbauen V = mex_build_V(coordinates,elements,zeta{i},typ(i)); + if(~vcon) x = V\b; else @@ -197,7 +205,7 @@ for j = 1:times % save_x{i} = x; - +end_time = toc - start_time; dataS = [dataS ... typ(i) ... berechnet mit Typ @@ -207,10 +215,12 @@ for j = 1:times sqrt(sum(mu))... mu min(hmin)/max(hmax)... min(hmax)/max(hmax)... - min(hmin./hmax) con... + min(hmin./hmax)... + con... Kondition sqrt(sum(tmu2))... tilde mu 2 xe_fine... (kappa) kap3 ... kappa 3 + end_time ... benötigte Zeit (Aufbauen, Berechnen) ]; end diff --git a/src/gauss.hpp b/src/gauss.hpp index b88c18c..448b85e 100644 --- a/src/gauss.hpp +++ b/src/gauss.hpp @@ -31,9 +31,9 @@ typedef struct _gauss { double w; } gauss; -double const GAUSS_SIZE[] = { 1, 2, 4, 8, 16, 32 }; +double GAUSS_SIZE[] = { 1, 2, 4, 8, 16, 32 }; -gauss const GAUSS_NODES[][32] = { +gauss GAUSS_NODES[][32] = { { { 0.5, 1 }}, { diff --git a/src/mex_profiler.c b/src/mex_profiler.c new file mode 100644 index 0000000..cc05c1a --- /dev/null +++ b/src/mex_profiler.c @@ -0,0 +1,68 @@ +#include +#include +#include +#include +#include +#include "engine.h" + +typedef void (*mexFunction_t)(int nargout, mxArray *pargout [ ], int nargin, const mxArray *pargin[]); + +int main(int argc, const char *argv[]) + +{ + Engine *ep; + char buff[1024]; + int i; + + /* matlab must be in the PATH! */ + if (!(ep = engOpen("matlab -nodisplay"))) { + fprintf(stderr, "Can't start MATLAB engine\n"); + return -1; + } + engOutputBuffer(ep, buff, 1023); + + /* load the mex file */ + if(argc<2){ + fprintf(stderr, "Error. Give full path to the MEX file as input parameter.\n"); + return -1; + } + void *handle = dlopen(argv[1], RTLD_NOW); + if(!handle){ + fprintf(stderr, "Error loading MEX file: %s\n", strerror(errno)); + return -1; + } + + /* grab mexFunction handle */ + mexFunction_t mexfunction = (mexFunction_t)dlsym(handle, "mexFunction"); + if(!mexfunction){ + fprintf(stderr, "MEX file does not contain mexFunction\n"); + return -1; + } + + /* load input data - for convenience do that using MATLAB engine */ + /* NOTE: parameters are MEX-file specific, so one has to modify this*/ + /* to fit particular needs */ + engEvalString(ep, "load input.mat"); + mxArray *arg1 = engGetVariable(ep, "coordinates"); + mxArray *arg2 = engGetVariable(ep, "elements"); + mxArray *arg3 = engGetVariable(ep, "z"); + mxArray *arg4 = engGetVariable(ep, "t"); + mxArray *pargout[1] = {0}; + const mxArray *pargin[4] = {arg1, arg2, arg3, arg4}; + + /* execute the mex function */ + mexfunction(1, pargout, 4, pargin); + + /* print the results using MATLAB engine */ + engPutVariable(ep, "result", pargout[0]); + engEvalString(ep, "result"); + printf("%s\n", buff); + + /* cleanup */ + mxDestroyArray(pargout[0]); + engEvalString(ep, "clear all;"); + dlclose(handle); + engClose(ep); + + return 0; +} diff --git a/src/profile.sh b/src/profile.sh new file mode 100755 index 0000000..6967acf --- /dev/null +++ b/src/profile.sh @@ -0,0 +1 @@ +PATH=$PATH:/opt/MATLAB/R2012a/bin/ LD_LIBRARY_PATH=/opt/MATLAB/R2012a/bin/glnxa64/:/opt/MATLAB/R2012a/sys/os/glnxa64/ valgrind --tool=callgrind ./mex_profiler ./mex_build_V.mexa64 diff --git a/src/slpRectangle.cpp b/src/slpRectangle.cpp index 70c303f..8b96fbc 100644 --- a/src/slpRectangle.cpp +++ b/src/slpRectangle.cpp @@ -22,15 +22,18 @@ #include "gauss.hpp" //#define quad 2 // Anzahl der Quadratur Auswertungstellen 2^quad -int quad = 2; +//int quad = 2; +int GAUSS_size = GAUSS_SIZE[2]; +gauss * GAUSS_nodes = GAUSS_NODES[2]; //using namespace std; int setQuad(int q) { - quad = q; - return GAUSS_SIZE[quad]; + GAUSS_size = GAUSS_SIZE[q]; + GAUSS_nodes = GAUSS_NODES[q]; + return GAUSS_size; } -int sign(double); +int inline sign(double); //double arsinh(double); /* ============================== */ @@ -209,11 +212,11 @@ double inline g_QY(double p, double y, double x, double l) { double sol = 0; - for (int i = 0; i < GAUSS_SIZE[quad]; ++i) { + for (int i = 0; i < GAUSS_size; ++i) { sol += pow( - (x - GAUSS_NODES[quad][i].n * y) - * (x - GAUSS_NODES[quad][i].n * y) + l * l, p) - * GAUSS_NODES[quad][i].w * y; + (x - GAUSS_nodes[i].n * y) + * (x - GAUSS_nodes[i].n * y) + l * l, p) + * GAUSS_nodes[i].w * y; } return sol; @@ -255,15 +258,15 @@ double inline G_QY1Y2(double p, double y1, double y2, double x1, double x2, double l) { double sol = 0; - for (int i = 0; i < GAUSS_SIZE[quad]; ++i) { - for (int j = 0; j < GAUSS_SIZE[quad]; ++j) { + for (int i = 0; i < GAUSS_size; ++i) { + for (int j = 0; j < GAUSS_size; ++j) { sol += pow( - (x1 - y1 * GAUSS_NODES[quad][i].n) - * (x1 - y1 * GAUSS_NODES[quad][i].n) - + (x2 - y2 * GAUSS_NODES[quad][j].n) - * (x2 - y2 * GAUSS_NODES[quad][j].n) - + l * l, p) * y1 * GAUSS_NODES[quad][i].w * y2 - * GAUSS_NODES[quad][j].w; + (x1 - y1 * GAUSS_nodes[i].n) + * (x1 - y1 * GAUSS_nodes[i].n) + + (x2 - y2 * GAUSS_nodes[j].n) + * (x2 - y2 * GAUSS_nodes[j].n) + + l * l, p) * y1 * GAUSS_nodes[i].w * y2 + * GAUSS_nodes[j].w; } } return sol; @@ -416,22 +419,20 @@ template double intQ2A2(double b, double d, double t, double v, double d1, double d2, double d3) { double sol = 0; - - for (int i = 0; i < GAUSS_SIZE[quad]; ++i) { - for (int j = 0; j < GAUSS_SIZE[quad]; ++j) { - sol += (F(b * GAUSS_NODES[quad][i].n, d * GAUSS_NODES[quad][j].n, t, - v, d1, d2, d3) - - F(b * GAUSS_NODES[quad][i].n, d * GAUSS_NODES[quad][j].n, - 0, v, d1, d2, d3) - - F(b * GAUSS_NODES[quad][i].n, d * GAUSS_NODES[quad][j].n, - t, 0, d1, d2, d3) - + F(b * GAUSS_NODES[quad][i].n, d * GAUSS_NODES[quad][j].n, - 0, 0, d1, d2, d3)) * GAUSS_NODES[quad][i].w - * GAUSS_NODES[quad][j].w * b * d; + double w1, x1, x2; + + for (int i = 0; i < GAUSS_size; ++i) { + x1 = b * GAUSS_nodes[i].n; + w1 = GAUSS_nodes[i].w; + for (int j = 0; j < GAUSS_size; ++j) { + x2 = d * GAUSS_nodes[j].n; + sol += (F(x1, x2, t, v, d1, d2, d3) - F(x1, x2, 0, v, d1, d2, d3) + - F(x1, x2, t, 0, d1, d2, d3) + F(x1, x2, 0, 0, d1, d2, d3)) + * w1 * GAUSS_nodes[j].w; } } - return sol; + return sol * b * d; } /* @@ -444,24 +445,27 @@ double intQ4(double b, double d, double t, double v, double d1, double d2, double sol = 0; int i, j, k, l; - - for (i = 0; i < GAUSS_SIZE[quad]; ++i) { - for (j = 0; j < GAUSS_SIZE[quad]; ++j) { - for (k = 0; k < GAUSS_SIZE[quad]; ++k) { - for (l = 0; l < GAUSS_SIZE[quad]; ++l) { - sol += F(b * GAUSS_NODES[quad][i].n, - d * GAUSS_NODES[quad][j].n, - t * GAUSS_NODES[quad][k].n, - v * GAUSS_NODES[quad][l].n, d1, d2, d3) * b * d * t - * v * GAUSS_NODES[quad][i].w - * GAUSS_NODES[quad][j].w * GAUSS_NODES[quad][k].w - * GAUSS_NODES[quad][l].w; + double x1, x2, y1; + double w1, w2, w3; + + for (i = 0; i < GAUSS_size; ++i) { + x1 = b * GAUSS_nodes[i].n; + w1 = GAUSS_nodes[i].w; + for (j = 0; j < GAUSS_size; ++j) { + x2 = d * GAUSS_nodes[j].n; + w2 = w1 * GAUSS_nodes[j].w; + for (k = 0; k < GAUSS_size; ++k) { + y1 = t * GAUSS_nodes[k].n; + w3 = w2 * GAUSS_nodes[k].w; + for (l = 0; l < GAUSS_size; ++l) { + sol += F(x1, x2, y1, v * GAUSS_nodes[l].n, d1, d2, d3) * w3 + * GAUSS_nodes[l].w; } } } } - return sol; + return sol * b * d * t * v; } /*