Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding an environment info example

  • Loading branch information...
commit df3bb252205b4466971c85ef05d046234470d497 1 parent 7467c9a
@strassek strassek authored
View
10 openmp_basics/environment/Makefile
@@ -0,0 +1,10 @@
+default: getEnvInfo
+
+getEnvInfo.o: getEnvInfo.c
+ gcc -c getEnvInfo.c -fopenmp
+
+getEnvInfo: getEnvInfo.o
+ gcc -o getEnvInfo getEnvInfo.o -fopenmp
+
+clean:
+ rm -f *.o getEnvInfo
View
52 openmp_basics/environment/getEnvInfo.c
@@ -0,0 +1,52 @@
+/******************************************************************************
+* FILE: omp_getEnvInfo.c
+* DESCRIPTION:
+* OpenMP Example - Get Environment Information - C/C++ Version
+* The master thread queries and prints selected environment information.
+* AUTHOR: Blaise Barney 7/06
+* LAST REVISED: 07/12/06
+******************************************************************************/
+
+#include <omp.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main (int argc, char *argv[])
+{
+int nthreads, tid, procs, maxt, inpar, dynamic, nested;
+
+/* Start parallel region */
+#pragma omp parallel private(nthreads, tid)
+ {
+
+ /* Obtain thread number */
+ tid = omp_get_thread_num();
+
+ /* Only master thread does this */
+ if (tid == 0)
+ {
+ printf("Thread %d getting environment info...\n", tid);
+
+ /* Get environment information */
+ procs = omp_get_num_procs();
+ nthreads = omp_get_num_threads();
+ maxt = omp_get_max_threads();
+ inpar = omp_in_parallel();
+ dynamic = omp_get_dynamic();
+ nested = omp_get_nested();
+
+ /* Print environment information */
+ printf("Number of processors = %d\n", procs);
+ printf("Number of threads = %d\n", nthreads);
+ printf("Max threads = %d\n", maxt);
+ printf("In parallel? = %d\n", inpar);
+ printf("Dynamic threads enabled? = %d\n", dynamic);
+ printf("Nested parallelism supported? = %d\n", nested);
+
+ }
+
+ } /* Done */
+
+}
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.