#ifdef _CONSOLE #include #include #include #include #else #include "omp.h" #endif #define NPROCS 2 /*set to number of physical processors*/ /* Copyright (C) by Bob Cook , 2006. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. Write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ void test() { float x[1000],y[1000],z; int i,j,k,m; char *s; double start,stop,local; printf("********************************************************\n"); printf("*******BEGIN SEPARATE COMPILATION TESTS*****************\n"); #ifndef _OPENMP printf("#E _OPENMP not defined err#1\n"); #endif printf("%d threads should start\n",omp_get_num_threads()); i=0; #pragma omp parallel { printf("Thread %d running.\n",omp_get_thread_num()); #pragma atomic i++; } printf("%d threads should have stopped\n",omp_get_num_threads()); if (i!=omp_get_num_threads()) printf("#E error atomic #1\n"); printf("********************************************************\n"); printf("*********END SEPARATE COMPILATION TESTS*****************\n"); printf("********************************************************\n"); printf("******************BEGIN UNARY TESTS*********************\n"); printf("1 thread should start\n"); j=0; #pragma omp parallel for schedule(static) num_threads(1) for (i=0; i<9; i++) { #pragma omp atomic j++; } printf("1 thread should have stopped\n"); if (j!=9) printf("#E omp sched static err#2\n"); printf("1 thread should start\n"); j=0; #pragma omp parallel for schedule(static,1) num_threads(1) for (i=0; i<9; i++) { #pragma omp atomic j++; } printf("1 thread should have stopped\n"); if (j!=9) printf("#E omp sched static,1 err#3\n"); printf("1 thread should start\n"); j=0; #pragma omp parallel for schedule(static,4) num_threads(1) for (i=0; i<9; i++) { #pragma omp atomic j++; } printf("1 thread should have stopped\n"); if (j!=9) printf("#E omp sched static,4 err#4\n"); printf("1 thread should start\n"); j=0; #pragma omp parallel for schedule(static,3) num_threads(1) for (i=9; i>-2; i=i-1) { #pragma omp atomic j++; } printf("1 thread should have stopped\n"); if (j!=11) printf("#E omp sched static,3 err#5\n"); printf("1 thread should start\n"); j=0; #pragma omp parallel for schedule(dynamic,2) num_threads(1) for (i=0; i<9; i++) { #pragma omp atomic j++; } printf("1 thread should have stopped\n"); if (j!=9) printf("#E omp sched dynamic,2 err#6\n"); printf("1 thread should start\n"); j=0; #pragma omp parallel for schedule(guided) num_threads(1) for (i=0; i<9; i++) { #pragma omp atomic j++; } printf("1 thread should have stopped\n"); if (j!=9) printf("#E omp sched guided err#7\n"); printf("1 thread should start\n"); j=0; #pragma omp parallel for schedule(guided,2) num_threads(1) for (i=0; i<9; i++) { #pragma omp atomic j++; } printf("1 thread should have stopped\n"); if (j!=9) printf("#E omp sched guided,2 err#8\n"); printf("********************************************************\n"); printf("********************END UNARY TESTS*********************\n"); }