~ubuntu-branches/ubuntu/wily/freefem++/wily

« back to all changes in this revision

Viewing changes to examples++-load/dmatrix.hpp

  • Committer: Package Import Robot
  • Author(s): Dimitrios Eftaxiopoulos, Dimitrios Eftaxiopoulos, Christophe Trophime
  • Date: 2013-09-12 00:02:58 UTC
  • mfrom: (1.2.1) (11.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130912000258-aclq2zfa1svt0p3x
Tags: 3.25-1
[ Dimitrios Eftaxiopoulos ]
* Imported Upstream version 3.25 (Closes: #701161 #706714)
* Change installation directory of header-like *.idp files
  from /usr/lib/freefem++ to /usr/include/freefem++, in order
  to fix a lintian warning
* Update patch to examples++-load/Makefile.am in order to enable
  functioning of load *.so and include *.idp commands in *.edp
  scripts
* Delete patches to src/Graphics/sansgraph.cpp and
  src/Graphics/xglrgraph.cpp because they are not needed any more
* Fix lintian warning about missing LDFLAGS
* Override dh_auto_test in debian/rules, such that in case it is 
  used, it completes executing all *.edp example files, regardless
  of aborting on some of them
* Add libmetis-dev to build-deps in d/control
* Remove libparmetis-dev from build deps
* Add --parallel option to dh $@ in debian/rules
* Add hardening compilation flags to mpic++
* Allow testing of compiling and running the example files after build

[ Christophe Trophime ]
* update C. Trophime email
* add support for nlopt, ipopt - simplify debian/rules
* upload CT changes to 3.20
* add patch for configure
* add patch for examples++-mpi
* fix bamg install
* add corrected scripts to build plugins
* add patch for properly build examples++-load
* add lintian overrides for libfreefem++
* add some missing files
* update patches
* update rules
* reorder BuildDepends - comment out unsupported libs

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// SUMMARY  :   matrix manipulation
 
2
// USAGE    : LGPL      
 
3
// ORG      : LJLL Universite Pierre et Marie Curie, Paris,  FRANCE 
 
4
// AUTHOR   : P. Jolivet 
 
5
// E-MAIL   : Pierre Jolivet <pierre.jolivet@ljll.math.upmc.fr>
 
6
//
 
7
 
 
8
/* 
 
9
 This file is part of Freefem++
 
10
 
 
11
 Freefem++ is free software; you can redistribute it and/or modify
 
12
 it under the terms of the GNU Lesser General Public License as published by
 
13
 the Free Software Foundation; either version 2.1 of the License, or
 
14
 (at your option) any later version.
 
15
 
 
16
 Freefem++  is distributed in the hope that it will be useful,
 
17
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
 GNU Lesser General Public License for more details.
 
20
 
 
21
 You should have received a copy of the GNU Lesser General Public License
 
22
 along with Freefem++; if not, write to the Free Software
 
23
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
24
 
 
25
 */
 
26
 
 
27
#include <vector>
 
28
//#include <mpi.h>
 
29
#include <iostream>
 
30
#include <numeric>
 
31
 
 
32
struct step {
 
33
    public:
 
34
        step(int x, int y) : x(x), y(y) { }
 
35
        int operator()() { return x += y; }
 
36
 
 
37
    private:
 
38
        int x, y;
 
39
};
 
40
 
 
41
template<unsigned char M, unsigned char S>
 
42
static void CSR2COO(unsigned int n, int* compressedI, int* uncompressedI) {
 
43
    if(S == 'U') {
 
44
        for(int i = n - 1; i > -1; --i) {
 
45
            if(M == 'F')
 
46
                std::fill(uncompressedI + compressedI[i] - 1, uncompressedI + compressedI[i + 1] - 1, i + 1);
 
47
            else
 
48
                std::fill(uncompressedI + compressedI[i], uncompressedI + compressedI[i + 1], i + 1);
 
49
        }
 
50
    }
 
51
    else if(S == 'L') {
 
52
        for(int i = 1; i < n; ++i) {
 
53
            if(M == 'F')
 
54
                std::fill(uncompressedI + compressedI[i] - i - 1, uncompressedI + compressedI[i + 1] - i - 1, i + 1);
 
55
            else
 
56
                std::fill(uncompressedI + compressedI[i] - i, uncompressedI + compressedI[i + 1] - i - 1, i + 1);
 
57
        }
 
58
    }
 
59
};
 
60
 
 
61
template<bool WithDiagonal, unsigned char N,typename Scalar>
 
62
static unsigned int trimCSR(unsigned int n, int* trimmedI, int* untrimmedI, int* trimmedJ, int* untrimmedJ, Scalar* trimmedC, Scalar* untrimmedC) {
 
63
    unsigned int upper = 0;
 
64
    for(unsigned int i = 0; i < n - WithDiagonal; ++i) {
 
65
        trimmedI[i] = upper + (N == 'F');
 
66
        int* jIndex = lower_bound(untrimmedJ + untrimmedI[i], untrimmedJ + untrimmedI[i + 1], i + !WithDiagonal);
 
67
        unsigned int j = untrimmedI[i] + jIndex - (untrimmedJ + untrimmedI[i]);
 
68
        if(N == 'F') {
 
69
            for(unsigned int k = j; k < untrimmedI[i + 1]; ++k)
 
70
                trimmedJ[upper + k - j] = untrimmedJ[k] + 1;
 
71
 
 
72
        } else
 
73
            std::copy(untrimmedJ + j, untrimmedJ + untrimmedI[i + 1], trimmedJ + upper);
 
74
        std::copy(untrimmedC + j, untrimmedC + untrimmedI[i + 1], trimmedC + upper);
 
75
        upper += untrimmedI[i + 1] - j;
 
76
    }
 
77
    if(WithDiagonal) {
 
78
        trimmedI[n - 1] = upper + (N == 'F');
 
79
        trimmedI[n] = trimmedI[n - 1] + 1;
 
80
        trimmedJ[upper] = n - (N == 'C');
 
81
        trimmedC[upper] = untrimmedC[untrimmedI[n] - 1];
 
82
        return trimmedI[n];
 
83
    }
 
84
    else {
 
85
        trimmedI[n] = trimmedI[n - 1];
 
86
        return trimmedI[n + 1];
 
87
    }
 
88
};