6 merge requests!368Update prace.md to document the change from qprace to qprod as the default...,!367Update prace.md to document the change from qprace to qprod as the default...,!366Update prace.md to document the change from qprace to qprod as the default...,!323extended-acls-storage-section,!196Master,!161Gajdusek cleaning
@@ -193,79 +193,79 @@ One way of paralelization a code for Xeon Phi is using OpenMP directives. The fo
...
@@ -193,79 +193,79 @@ One way of paralelization a code for Xeon Phi is using OpenMP directives. The fo
```console
```console
$cat ./vect-add
$cat ./vect-add
#include <stdio.h>
#include <stdio.h>
typedef int T;
typedef int T;
#define SIZE 1000
#define SIZE 1000
#pragma offload_attribute(push, target(mic))
#pragma offload_attribute(push, target(mic))
T in1[SIZE];
T in1[SIZE];
T in2[SIZE];
T in2[SIZE];
T res[SIZE];
T res[SIZE];
#pragma offload_attribute(pop)
#pragma offload_attribute(pop)
// MIC function to add two vectors
// MIC function to add two vectors
__attribute__((target(mic))) add_mic(T *a, T *b, T *c, int size) {
__attribute__((target(mic))) add_mic(T *a, T *b, T *c, int size) {
int i = 0;
int i = 0;
#pragma omp parallel for
#pragma omp parallel for
for (i = 0;i < size; i++)
for (i = 0;i < size; i++)
c[i] = a[i] + b[i];
c[i] = a[i] + b[i];
}
}
// CPU function to add two vectors
// CPU function to add two vectors
void add_cpu (T *a, T *b, T *c, int size) {
void add_cpu (T *a, T *b, T *c, int size) {
int i;
int i;
for (i = 0;i < size; i++)
for (i = 0;i < size; i++)
c[i] = a[i] + b[i];
c[i] = a[i] + b[i];
}
}
// CPU function to generate a vector of random numbers
// CPU function to generate a vector of random numbers
void random_T (T *a, int size) {
void random_T (T *a, int size) {
int i;
int i;
for (i = 0;i < size; i++)
for (i = 0;i < size; i++)
a[i] = rand() % 10000;// random number between 0 and 9999
a[i] = rand() % 10000;// random number between 0 and 9999
}
}
// CPU function to compare two vectors
// CPU function to compare two vectors
int compare(T *a, T *b, T size ){
int compare(T *a, T *b, T size ){
int pass = 0;
int pass = 0;
int i;
int i;
for (i = 0;i < size; i++){
for (i = 0;i < size; i++){
if (a[i] != b[i]) {
if (a[i] != b[i]) {
printf("Value mismatch at location %d, values %d and %dn",i, a[i], b[i]);
printf("Value mismatch at location %d, values %d and %dn",i, a[i], b[i]);
pass = 1;
pass = 1;
}
}
if (pass == 0) printf ("Test passedn");else printf("Test Failedn");
return pass;
}
}
}
if (pass == 0) printf ("Test passedn");else printf("Test Failedn");
return pass;
}
int main()
int main()
{
{
int i;
int i;
random_T(in1, SIZE);
random_T(in1, SIZE);
random_T(in2, SIZE);
random_T(in2, SIZE);
#pragma offload target(mic)in(in1,in2) inout(res)
#pragma offload target(mic)in(in1,in2) inout(res)
{
{
// Parallel loop from main function
// Parallel loop from main function
#pragma omp parallel for
#pragma omp parallel for
for (i=0;i<SIZE; i++)
for (i=0;i<SIZE; i++)
res[i] = in1[i] + in2[i];
res[i] = in1[i] + in2[i];
// or parallel loop is called inside the function
// or parallel loop is called inside the function
add_mic(in1, in2, res, SIZE);
add_mic(in1, in2, res, SIZE);
}
}
//Check the results with CPU implementation
//Check the results with CPU implementation
T res_cpu[SIZE];
T res_cpu[SIZE];
add_cpu(in1, in2, res_cpu, SIZE);
add_cpu(in1, in2, res_cpu, SIZE);
compare(res, res_cpu, SIZE);
compare(res, res_cpu, SIZE);
}
}
```
```
During the compilation Intel compiler shows which loops have been vectorized in both host and accelerator. This can be enabled with compiler option "-vec-report2". To compile and execute the code run
During the compilation Intel compiler shows which loops have been vectorized in both host and accelerator. This can be enabled with compiler option "-vec-report2". To compile and execute the code run
An example of basic MPI version of "hello-world" example in C language, that can be executed on both host and Xeon Phi is (can be directly copy and pasted to a .c file)
An example of basic MPI version of "hello-world" example in C language, that can be executed on both host and Xeon Phi is (can be directly copy and pasted to a .c file)
```cpp
```cpp
#include<stdio.h>
#include<stdio.h>
#include<mpi.h>
#include<mpi.h>
intmain(argc,argv)
intmain(argc,argv)
intargc;
intargc;
char*argv[];
char*argv[];
{
{
intrank,size;
intrank,size;
intlen;
intlen;
charnode[MPI_MAX_PROCESSOR_NAME];
charnode[MPI_MAX_PROCESSOR_NAME];
MPI_Init(&argc,&argv);/* starts MPI */
MPI_Init(&argc,&argv);/* starts MPI */
MPI_Comm_rank(MPI_COMM_WORLD,&rank);/* get current process id */
MPI_Comm_rank(MPI_COMM_WORLD,&rank);/* get current process id */
MPI_Comm_size(MPI_COMM_WORLD,&size);/* get number of processes */
MPI_Comm_size(MPI_COMM_WORLD,&size);/* get number of processes */
MPI_Get_processor_name(node,&len);
MPI_Get_processor_name(node,&len);
printf("Hello world from process %d of %d on host %s n",rank,size,node);
printf("Hello world from process %d of %d on host %s n",rank,size,node);