Intel® C++ Compiler XE 13.1 User and Reference Guides
This topic only applies to Intel® MIC Architecture.
This sample program, sample.c, uses the F32vec16 class to average the elements of an 80 element floating point array.
To generate the object file a.out, which only runs on Intel® MIC Architecture, compile the following code with the following command:
icc -mmic sample.c
// Include Vector Class Definitions
#include <micvec.h>
#include <stdio.h>
#define SIZE 80
// Global variables
float result;
__declspec(align(64)) float array[SIZE];
//*****************************************************
// Function: Add80ArrayElements
// Add all the elements of a 80 element array
//*****************************************************
void Add80ArrayElements (F32vec16 *array, float *result)
{
F32vec16 vec0, vec1;
vec0 = _mm512_load_ps((char*)array); // Load array's first 16 floats
//*****************************************************
// Add all elements of the array, 16 elements at a time
//******************************************************
vec0 += array[1]; // Add elements 17-32
vec0 += array[2]; // Add elements 33-48
vec0 += array[3]; // Add elements 49-64
vec0 += array[4]; // Add elements 65-80
//*****************************************************
// Add all elements in resulting vector
//******************************************************
*result = _mm512_reduce_add_ps(vec0);
}
int main(int argc, char *argv[])
{
int i;
// Initialize the array
for (i=0; i < SIZE; i++) {
array[i] = (float) i;
}
// Call function to add all array elements
Add80ArrayElements ((F32vec16*)array, &result);
// Print average array element value
printf ("Average of all array values = %f\n", result/80.);
printf ("The correct answer is %f\n\n\n", 39.5);
return 0;
}