Changes

Jump to: navigation, search

DPS921/Intel Advisor

2,826 bytes added, 13:16, 2 December 2020
Code Example
== Code Example ==
<source>
//==============================================================
//
// SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT,
// http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/
//
// Copyright 2017 Intel Corporation
//
// THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT
// NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS.
//
// =============================================================
#include <iostream>
#include <random>
#include <vector>
using namespace std;
 
#define REPEAT 3000
#define SIZE 70000
 
// Despite the name, the vector data type has nothing to do with SIMD vectors.
// To avoid confusion, I'm renaming the data type to "dynamic_array".
typedef vector<double> dynamic_array;
 
int dummy = 0;
 
double doublesArray[SIZE * 2];
float floatsArray[SIZE];
dynamic_array firstDynamic(SIZE);
dynamic_array secondDynamic(SIZE);
 
int main()
{
for (int i = 0; i < SIZE; i++)
{
firstDynamic[i] = doublesArray[i] = (rand() % 5000) + 1.0;
secondDynamic[i] = doublesArray[i + SIZE] = (rand() % 5000) + 1.0;
floatsArray[i] = (rand() % 5000) + 1.0f;
}
/****************** Normal Unit Stride Loop ******************/
cout << "Normal Unit Stride Loop: ";
for (int r = 0; r < REPEAT; r++)
{
for (int i = 0; i < SIZE; i++)
{
doublesArray[i] = i * 42.0 + 7;
}
}
cout << "DONE\n";
/****************** Vector Length Demo Loop ******************/
cout << "Vector Length Demo Loop: ";
for (int r = 0; r < REPEAT; r++)
{
for (int i = 0; i < SIZE; i++)
{
floatsArray[i] = i * 42.0f + 7;
}
}
cout << "DONE\n";
/******************** Constant Stride Loop *******************/
cout << "Constant Stride Loop: ";
for (int r = 0; r < REPEAT; r++)
{
dummy++; // Prevents interchange. Too fast to contribute to loop time.
for (int i = 0; i < SIZE; i++)
{
doublesArray[i * 2] = i * 42.0 + 7;
}
}
cout << "DONE\n";
/******************** Variable Stride Loop *******************/
cout << "Variable Stride Loop: ";
for (int r = 0; r < REPEAT; r++)
{
for (int i = 0; i < SIZE; i++)
{
doublesArray[i + (i / 2)] = i * 42.0 + 7;
}
}
cout << "DONE\n";
/******************** True Dependency Loop *******************/
cout << "True Dependency Loop: ";
for (int r = 0; r < REPEAT; r++)
{
for (int i = 1; i < SIZE; i++)
{
doublesArray[i] = i * 42.0 + doublesArray[i - 1];
}
}
cout << "DONE\n";
/****************** Assumed Dependency Loop ******************/
cout << "Assumed Dependency Loop: ";
for (int r = 0; r < REPEAT; r++)
{
for (int i = 0; i < SIZE; i++)
{
firstDynamic[i] = i * 42.0 + secondDynamic[i];
}
}
cout << "DONE\n";
return EXIT_SUCCESS;
}
</source>
58
edits

Navigation menu