# Simplest Example...

## Simplest Example...

Are there any really simple examples?

3 posts / 0 новое
Пожалуйста, обратитесь к странице Уведомление об оптимизации для более подробной информации относительно производительности и оптимизации в программных продуктах компании Intel.

The Intel ArBB tutorials contain some very simple examples, such as computing the sum of two vectors and the dot-product of two vectors.

Take a look at Intel ArBB tutorials at: http://software.intel.com/sites/products/documentation/arbb/tutorial/index.htm.

Here is a simple example that adds two dense containers:

#include
#include
#include

using namespace arbb;

void add(dense& out, dense a, dense b)
{
out = a + b;
}

int main(int argc, char* argv[])
{
std::size_t size = 100; // operating on 100 elements

// vectors of floats to store data for a, b, c
std::vector a_data(size), b_data(size), c_data(size);

try {
dense a, b, c;

// bind data to arbb containers
bind(a, &a_data[0], a_data.size());
bind(b, &b_data[0], b_data.size());
bind(c, &c_data[0], c_data.size());

for (std::size_t i = 0; i < b_data.size(); ++i) {
b_data[i] = 2.0f; // or rand() or something more useful
c_daat[i] = 3.0f;
}

// call add with a as input/output and b and c as inputs

} catch (exception& e) {
std::cout << "exception thrown: " << e.what() << std::endl;
return 1;
}

// result is in a_data
for (std::size_t i = 0; i < a_data.size(); ++i) {
std::cout << i << " " << a_data[i] << std::endl;
}

return 0;
}