63 lines · c
1// RUN: %libomp-compile-and-run2// XFAIL: gcc-4, gcc-5, clang-3.7, clang-3.8, icc-15, icc-163#include <stdio.h>4#include <stdlib.h>5#include "omp_testsuite.h"6 7#ifndef N8#define N 7509#endif10 11int test_doacross() {12 int i, j;13 // Allocate and zero out the matrix14 int *m = (int *)malloc(sizeof(int) * N * N);15 for (i = 0; i < N; ++i) {16 for (j = 0; j < N; ++j) {17 m[i * N + j] = 0;18 }19 }20 // Have first row and column be 0, 1, 2, 3, etc.21 for (i = 0; i < N; ++i)22 m[i * N] = i;23 for (j = 0; j < N; ++j)24 m[j] = j;25 // Perform wavefront which results in matrix:26 // 0 1 2 3 427 // 1 2 3 4 528 // 2 3 4 5 629 // 3 4 5 6 730 // 4 5 6 7 831 #pragma omp parallel shared(m)32 {33 int row, col;34 #pragma omp for ordered(2)35 for (row = 1; row < N; ++row) {36 for (col = 1; col < N; ++col) {37 #pragma omp ordered depend(sink : row - 1, col) depend(sink : row, col - 1)38 m[row * N + col] = m[(row - 1) * N + col] + m[row * N + (col - 1)] -39 m[(row - 1) * N + (col - 1)];40 #pragma omp ordered depend(source)41 }42 }43 }44 45 // Check the bottom right element to see if iteration dependencies were held46 int retval = (m[(N - 1) * N + N - 1] == 2 * (N - 1));47 free(m);48 return retval;49}50 51int main(int argc, char **argv) {52 int i;53 int num_failed = 0;54 if (omp_get_max_threads() < 2)55 omp_set_num_threads(4);56 for (i = 0; i < REPETITIONS; i++) {57 if (!test_doacross()) {58 num_failed++;59 }60 }61 return num_failed;62}63