]> git.leopard-lacewing.eu Git - bacc.git/commitdiff
[src]Zeitmessung + plotten
authorPeter Schaefer <peter.schaefer@tuwien.ac.at>
Wed, 27 Mar 2013 11:27:09 +0000 (12:27 +0100)
committerPeter Schaefer <peter.schaefer@tuwien.ac.at>
Wed, 27 Mar 2013 11:32:52 +0000 (12:32 +0100)
[src]mex Profiler hinzugefügt
[src]kleine Laufzeit optimierungen

src/A_plots.m
src/compute.m
src/gauss.hpp
src/mex_profiler.c [new file with mode: 0644]
src/profile.sh [new file with mode: 0755]
src/slpRectangle.cpp

index 84a2918344b5d4f627325a5d1b247ed00112f03f..5428519354447ef037017280f816dbebdb4c100e 100644 (file)
@@ -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
index 7cbab1f5e626152ad1750427fab782381f3fe58e..730d896856dcfff72d54e028ef8f2fdf7f2a7b30 100644 (file)
@@ -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
 
index b88c18c9c4767bae75f23351958d708c54c9e244..448b85e3fe3369e946f5561e13da39cb50ee1914 100644 (file)
@@ -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 (file)
index 0000000..cc05c1a
--- /dev/null
@@ -0,0 +1,68 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <dlfcn.h>
+#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 (executable)
index 0000000..6967acf
--- /dev/null
@@ -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
index 70c303f5fd1ed2b8eb76b5c82f119a3b983454bb..8b96fbc1dfbc495986a8158cfc1a022d02593cd5 100644 (file)
 #include "gauss.hpp"\r
 \r
 //#define quad 2       // Anzahl der Quadratur Auswertungstellen 2^quad\r
-int quad = 2;\r
+//int quad = 2;\r
+int GAUSS_size = GAUSS_SIZE[2];\r
+gauss * GAUSS_nodes = GAUSS_NODES[2];\r
 //using namespace std;\r
 \r
 int setQuad(int q) {\r
-       quad = q;\r
-       return GAUSS_SIZE[quad];\r
+       GAUSS_size = GAUSS_SIZE[q];\r
+       GAUSS_nodes = GAUSS_NODES[q];\r
+       return GAUSS_size;\r
 }\r
 \r
-int sign(double);\r
+int inline sign(double);\r
 //double arsinh(double);\r
 \r
 /* ============================== */\r
@@ -209,11 +212,11 @@ double inline g_QY(double p, double y, double x, double l) {
 \r
        double sol = 0;\r
 \r
-       for (int i = 0; i < GAUSS_SIZE[quad]; ++i) {\r
+       for (int i = 0; i < GAUSS_size; ++i) {\r
                sol += pow(\r
-                               (x - GAUSS_NODES[quad][i].n * y)\r
-                                               * (x - GAUSS_NODES[quad][i].n * y) + l * l, p)\r
-                               * GAUSS_NODES[quad][i].w * y;\r
+                               (x - GAUSS_nodes[i].n * y)\r
+                                               * (x - GAUSS_nodes[i].n * y) + l * l, p)\r
+                               * GAUSS_nodes[i].w * y;\r
        }\r
 \r
        return sol;\r
@@ -255,15 +258,15 @@ double inline G_QY1Y2(double p, double y1, double y2, double x1, double x2,
                double l) {\r
 \r
        double sol = 0;\r
-       for (int i = 0; i < GAUSS_SIZE[quad]; ++i) {\r
-               for (int j = 0; j < GAUSS_SIZE[quad]; ++j) {\r
+       for (int i = 0; i < GAUSS_size; ++i) {\r
+               for (int j = 0; j < GAUSS_size; ++j) {\r
                        sol += pow(\r
-                                       (x1 - y1 * GAUSS_NODES[quad][i].n)\r
-                                                       * (x1 - y1 * GAUSS_NODES[quad][i].n)\r
-                                                       + (x2 - y2 * GAUSS_NODES[quad][j].n)\r
-                                                                       * (x2 - y2 * GAUSS_NODES[quad][j].n)\r
-                                                       + l * l, p) * y1 * GAUSS_NODES[quad][i].w * y2\r
-                                       * GAUSS_NODES[quad][j].w;\r
+                                       (x1 - y1 * GAUSS_nodes[i].n)\r
+                                                       * (x1 - y1 * GAUSS_nodes[i].n)\r
+                                                       + (x2 - y2 * GAUSS_nodes[j].n)\r
+                                                                       * (x2 - y2 * GAUSS_nodes[j].n)\r
+                                                       + l * l, p) * y1 * GAUSS_nodes[i].w * y2\r
+                                       * GAUSS_nodes[j].w;\r
                }\r
        }\r
        return sol;\r
@@ -416,22 +419,20 @@ template<double (F)(double, double, double, double, double, double, double)>
 double intQ2A2(double b, double d, double t, double v, double d1, double d2,\r
                double d3) {\r
        double sol = 0;\r
-\r
-       for (int i = 0; i < GAUSS_SIZE[quad]; ++i) {\r
-               for (int j = 0; j < GAUSS_SIZE[quad]; ++j) {\r
-                       sol += (F(b * GAUSS_NODES[quad][i].n, d * GAUSS_NODES[quad][j].n, t,\r
-                                       v, d1, d2, d3)\r
-                                       - F(b * GAUSS_NODES[quad][i].n, d * GAUSS_NODES[quad][j].n,\r
-                                                       0, v, d1, d2, d3)\r
-                                       - F(b * GAUSS_NODES[quad][i].n, d * GAUSS_NODES[quad][j].n,\r
-                                                       t, 0, d1, d2, d3)\r
-                                       + F(b * GAUSS_NODES[quad][i].n, d * GAUSS_NODES[quad][j].n,\r
-                                                       0, 0, d1, d2, d3)) * GAUSS_NODES[quad][i].w\r
-                                       * GAUSS_NODES[quad][j].w * b * d;\r
+       double w1, x1, x2;\r
+\r
+       for (int i = 0; i < GAUSS_size; ++i) {\r
+               x1 = b * GAUSS_nodes[i].n;\r
+               w1 = GAUSS_nodes[i].w;\r
+               for (int j = 0; j < GAUSS_size; ++j) {\r
+                       x2 = d * GAUSS_nodes[j].n;\r
+                       sol += (F(x1, x2, t, v, d1, d2, d3) - F(x1, x2, 0, v, d1, d2, d3)\r
+                                       - F(x1, x2, t, 0, d1, d2, d3) + F(x1, x2, 0, 0, d1, d2, d3))\r
+                                       * w1 * GAUSS_nodes[j].w;\r
                }\r
        }\r
 \r
-       return sol;\r
+       return sol * b * d;\r
 }\r
 \r
 /*\r
@@ -444,24 +445,27 @@ double intQ4(double b, double d, double t, double v, double d1, double d2,
 \r
        double sol = 0;\r
        int i, j, k, l;\r
-\r
-       for (i = 0; i < GAUSS_SIZE[quad]; ++i) {\r
-               for (j = 0; j < GAUSS_SIZE[quad]; ++j) {\r
-                       for (k = 0; k < GAUSS_SIZE[quad]; ++k) {\r
-                               for (l = 0; l < GAUSS_SIZE[quad]; ++l) {\r
-                                       sol += F(b * GAUSS_NODES[quad][i].n,\r
-                                                       d * GAUSS_NODES[quad][j].n,\r
-                                                       t * GAUSS_NODES[quad][k].n,\r
-                                                       v * GAUSS_NODES[quad][l].n, d1, d2, d3) * b * d * t\r
-                                                       * v * GAUSS_NODES[quad][i].w\r
-                                                       * GAUSS_NODES[quad][j].w * GAUSS_NODES[quad][k].w\r
-                                                       * GAUSS_NODES[quad][l].w;\r
+       double x1, x2, y1;\r
+       double w1, w2, w3;\r
+\r
+       for (i = 0; i < GAUSS_size; ++i) {\r
+               x1 = b * GAUSS_nodes[i].n;\r
+               w1 = GAUSS_nodes[i].w;\r
+               for (j = 0; j < GAUSS_size; ++j) {\r
+                       x2 = d * GAUSS_nodes[j].n;\r
+                       w2 = w1 * GAUSS_nodes[j].w;\r
+                       for (k = 0; k < GAUSS_size; ++k) {\r
+                               y1 = t * GAUSS_nodes[k].n;\r
+                               w3 = w2 * GAUSS_nodes[k].w;\r
+                               for (l = 0; l < GAUSS_size; ++l) {\r
+                                       sol += F(x1, x2, y1, v * GAUSS_nodes[l].n, d1, d2, d3) * w3\r
+                                                       * GAUSS_nodes[l].w;\r
                                }\r
                        }\r
                }\r
        }\r
 \r
-       return sol;\r
+       return sol * b * d * t * v;\r
 }\r
 \r
 /*\r