All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
scheduler.cpp
Go to the documentation of this file.
/* =========================================================================
Copyright (c) 2010-2016, Institute for Microelectronics,
Institute for Analysis and Scientific Computing,
TU Wien.
Portions of this software are copyright by UChicago Argonne, LLC.
-----------------
ViennaCL - The Vienna Computing Library
-----------------
Project Head: Karl Rupp rupp@iue.tuwien.ac.at
(A list of authors and contributors can be found in the PDF manual)
License: MIT (X11), see file LICENSE in the base directory
============================================================================= */
// include necessary system headers
#include <iostream>
// include basic scalar and vector types of ViennaCL
#include "viennacl/scalar.hpp"
#include "viennacl/vector.hpp"
#include "viennacl/matrix.hpp"
#include "viennacl/scheduler/execute.hpp"
#include "viennacl/scheduler/io.hpp"
int main()
{
typedef float ScalarType; // do not change without adjusting the code for the low-level interface below
viennacl::vector<ScalarType> vcl_vec1(10);
viennacl::vector<ScalarType> vcl_vec2(10);
viennacl::vector<ScalarType> vcl_vec3(10);
for (unsigned int i = 0; i < 10; ++i)
{
vcl_vec1[i] = ScalarType(i);
vcl_vec2[i] = ScalarType(10 - i);
}
typedef viennacl::scheduler::statement::container_type NodeContainerType; // this is just std::vector<viennacl::scheduler::statement_node>
NodeContainerType expression_nodes(2); //container with two nodes
// specify LHS of first node, i.e. vcl_vec3:
expression_nodes[0].lhs.type_family = viennacl::scheduler::VECTOR_TYPE_FAMILY; // family of vectors
expression_nodes[0].lhs.subtype = viennacl::scheduler::DENSE_VECTOR_TYPE; // a dense vector
expression_nodes[0].lhs.numeric_type = viennacl::scheduler::FLOAT_TYPE; // vector consisting of floats
expression_nodes[0].lhs.vector_float = &vcl_vec3; // provide pointer to vcl_vec3;
// specify assignment operation for this node:
expression_nodes[0].op.type_family = viennacl::scheduler::OPERATION_BINARY_TYPE_FAMILY; // this is a binary operation, so both LHS and RHS operands are important
expression_nodes[0].op.type = viennacl::scheduler::OPERATION_BINARY_ASSIGN_TYPE; // assignment operation: '='
// specify RHS: Just refer to the second node:
expression_nodes[0].rhs.type_family = viennacl::scheduler::COMPOSITE_OPERATION_FAMILY; // this links to another node (no need to set .subtype and .numeric_type)
expression_nodes[0].rhs.node_index = 1; // index of the other node
// LHS
expression_nodes[1].lhs.type_family = viennacl::scheduler::VECTOR_TYPE_FAMILY; // family of vectors
expression_nodes[1].lhs.subtype = viennacl::scheduler::DENSE_VECTOR_TYPE; // a dense vector
expression_nodes[1].lhs.numeric_type = viennacl::scheduler::FLOAT_TYPE; // vector consisting of floats
expression_nodes[1].lhs.vector_float = &vcl_vec1; // provide pointer to vcl_vec1
// OP
expression_nodes[1].op.type_family = viennacl::scheduler::OPERATION_BINARY_TYPE_FAMILY; // this is a binary operation, so both LHS and RHS operands are important
expression_nodes[1].op.type = viennacl::scheduler::OPERATION_BINARY_ADD_TYPE; // addition operation: '+'
// RHS
expression_nodes[1].rhs.type_family = viennacl::scheduler::VECTOR_TYPE_FAMILY; // family of vectors
expression_nodes[1].rhs.subtype = viennacl::scheduler::DENSE_VECTOR_TYPE; // a dense vector
expression_nodes[1].rhs.numeric_type = viennacl::scheduler::FLOAT_TYPE; // vector consisting of floats
expression_nodes[1].rhs.vector_float = &vcl_vec2; // provide pointer to vcl_vec2
viennacl::scheduler::statement vec_addition(expression_nodes);
std::cout << vec_addition << std::endl;
viennacl::scheduler::execute(vec_addition);
std::cout << "vcl_vec1: " << vcl_vec1 << std::endl;
std::cout << "vcl_vec2: " << vcl_vec2 << std::endl;
std::cout << "vcl_vec3: " << vcl_vec3 << std::endl;
std::cout << "!!!! TUTORIAL COMPLETED SUCCESSFULLY !!!!" << std::endl;
return EXIT_SUCCESS;
}
matrix.hpp
Implementation of the dense matrix class.
viennacl::scheduler::DENSE_VECTOR_TYPE
Definition: forwards.h:271
io.hpp
Some helper routines for reading/writing/printing scheduler expressions.
viennacl::scheduler::execute
void execute(statement const &s)
Definition: execute.hpp:279
viennacl::scheduler::OPERATION_BINARY_ASSIGN_TYPE
Definition: forwards.h:115
viennacl::scheduler::COMPOSITE_OPERATION_FAMILY
Definition: forwards.h:251
viennacl::scheduler::statement::container_type
std::vector< value_type > container_type
Definition: forwards.h:507
viennacl::scheduler::OPERATION_BINARY_TYPE_FAMILY
Definition: forwards.h:59
viennacl::vector< ScalarType >
main
int main()
Definition: scheduler.cpp:119
vector.hpp
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
ScalarType
float ScalarType
Definition: fft_1d.cpp:42
execute.hpp
Provides the datastructures for dealing with a single statement such as 'x = y + z;'.
viennacl::scheduler::FLOAT_TYPE
Definition: forwards.h:299
viennacl::scheduler::statement
The main class for representing a statement such as x = inner_prod(y,z); at runtime.
Definition: forwards.h:502
viennacl::scheduler::OPERATION_BINARY_ADD_TYPE
Definition: forwards.h:118
scalar.hpp
Implementation of the ViennaCL scalar class.
viennacl::scheduler::VECTOR_TYPE_FAMILY
Definition: forwards.h:257