18
18
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
20
/// =========================================================================
21
#include "rheolef/vec_expr.h"
22
#include "rheolef/parstream.h"
21
#include "rheolef/vec_expr_ops.h"
22
#include "rheolef/diststream.h"
23
#include "rheolef/pretty_name.h"
23
24
using namespace rheolef;
24
25
using namespace std;
27
template <class Iterator>
29
check_iterator_access_raw (Iterator iter, size_t n) {
30
warning_macro ("iter: expr.size="<<n);
31
for (size_t i = 0; i < n; i++, iter++) {
32
warning_macro ("iter: expr["<<i<<"] = "<<*iter);
37
check_iterator_access (Expr e) {
38
check_iterator_access_raw (e.begin(), e.size());
42
check_subscript_access (Expr e) {
43
warning_macro ("sub: expr.size="<<e.size());
44
for (typename Expr::size_type i = 0, n = e.size(); i < n; i++) {
45
warning_macro ("sub: expr["<<i<<"] = "<< e[i]);
26
48
struct phi : unary_function<Float,Float> {
27
49
Float operator() (const Float& x) { return 2*x; }
29
51
int main(int argc, char**argv) {
30
environment parallel(argc, argv);
52
environment distributed(argc, argv);
31
53
size_t n = (argc < 2) ? 5 : atoi(argv[1]);
35
57
// set size and then assign:
38
pcout << "z = " << z.par_size() << endl;
60
dcout << "z = 2*x-y : z.dis_size = " << z.dis_size() << endl;
41
63
// size is zero and then assign:
44
pcout << "z1 = " << z1.par_size() << endl;
66
dcout << "z1.dis_size = " << z1.dis_size() << endl;
67
z1.put_values (dcout);
48
vec<Float> z2 = 2.*x - y;
49
pcout << "z2 = " << z2.par_size() << endl;
70
vec<Float> z2 = 2*x - y;
71
dcout << "z2.dis_size = " << z2.dis_size() << endl;
72
z2.put_values (dcout);
74
check_iterator_access (x+y);
75
check_subscript_access (x+y);
77
// dot with expression (lazy evaluation)
78
dcout << "dot(x, z) = " << dot(x, z) << endl;
79
dcout << "dot(x, 2*x-y) = " << dot(x, 2*x - y) << endl;
80
dcout << "dot(2*x-y, x) = " << dot(2*x-y, x) << endl;
81
dcout << "dot(3*x-y, 2*x-y) = " << dot(3*x-y, 2*x-y) << endl;
53
// set bad size and then assign:
84
// set bad size and then assign: it may exit(1)
54
85
vec<Float> z3(n+1);
56
pcout << "z3 = " << z3.size() << endl;
87
dcout << "z3 = " << z3.size() << endl;
88
z3.put_values (dcout);