Test for omp hello world (not yet working)
authorKevin Klues <klueska@cs.berkeley.edu>
Sat, 15 Dec 2012 05:22:09 +0000 (21:22 -0800)
committerKevin Klues <klueska@cs.berkeley.edu>
Sat, 15 Dec 2012 05:23:58 +0000 (21:23 -0800)
tests/Makefrag
tests/openmp/Makefrag [new file with mode: 0644]
tests/openmp/omp_hello.c [new file with mode: 0644]

index 7e9bc97..22dcbb5 100644 (file)
@@ -17,6 +17,7 @@ TESTS_EXECS  = $(patsubst $(TESTS_DIR)/%.c, \
                            $(TESTS_SRCS))
 
 include $(TESTS_DIR)/c3po/Makefrag
+include $(TESTS_DIR)/openmp/Makefrag
 
 STATIC := $(findstring static,$(TESTS_CFLAGS))
 $(OBJDIR)/$(TESTS_DIR)/%: $(TESTS_LDDEPENDS)
diff --git a/tests/openmp/Makefrag b/tests/openmp/Makefrag
new file mode 100644 (file)
index 0000000..35a088d
--- /dev/null
@@ -0,0 +1,28 @@
+OPENMP_TESTS_DIR = $(TESTS_DIR)/openmp
+
+OPENMP_TESTS_CFLAGS += $(TESTS_CFLAGS) \
+                     -fopenmp \
+                     -I$(GCC_ROOT)/$(TARGET_ARCH)-ros/sys-include/openmp
+
+ALL_OPENMP_TEST_FILES = $(shell ls $(OPENMP_TESTS_DIR)/*.c)
+
+OPENMP_TESTS_LDLIBS := 
+
+OPENMP_TESTS_SRCS := $(ALL_OPENMP_TEST_FILES)
+
+OPENMP_TESTS_LDDEPENDS := $(OPENMP_TESTS_DIR)/%.c 
+
+TESTS_EXECS  += $(patsubst $(OPENMP_TESTS_DIR)/%.c, \
+                      $(OBJDIR)/$(OPENMP_TESTS_DIR)/%, \
+                      $(OPENMP_TESTS_SRCS))
+
+STATIC := $(findstring static,$(OPENMP_TESTS_CFLAGS))
+$(OBJDIR)/$(OPENMP_TESTS_DIR)/%: $(OPENMP_TESTS_LDDEPENDS)
+       @echo + cc [OPENMP_TESTS] $<
+       @mkdir -p $(@D)
+       $(V)$(CC) $(OPENMP_TESTS_CFLAGS) -o $@ $(OPENMP_TESTS_LDFLAGS) \
+                 $(OPENMP_TESTS_LDDIRS) $< $(OPENMP_TESTS_LDLIBS)
+       @if [ "$(STATIC)" != "static" ]; then \
+               $(OBJDUMP) -S $@ > $@.asm; \
+               $(NM) -n $@ > $@.sym; \
+       fi
diff --git a/tests/openmp/omp_hello.c b/tests/openmp/omp_hello.c
new file mode 100644 (file)
index 0000000..07eccd7
--- /dev/null
@@ -0,0 +1,31 @@
+#include <sys/sysinfo.h>
+#include <omp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <vcore.h>
+
+int main (int argc, char *argv[]) 
+{
+  int nthreads, tid;
+  printf("get_nprocs: %d\n", get_nprocs());
+  printf("SC_NPROCESSORS_ONLN: %d\n", sysconf (_SC_NPROCESSORS_ONLN));
+  printf("max num vcores: %d\n", max_vcores());
+
+/* Fork a team of threads giving them their own copies of variables */
+#pragma omp parallel private(nthreads, tid)
+  {
+
+  /* Obtain thread number */
+  tid = omp_get_thread_num();
+  printf("Hello World from thread = %d\n", tid);
+
+  /* Only master thread does this */
+  if (tid == 0) 
+    {
+    nthreads = omp_get_num_threads();
+    printf("Number of threads = %d\n", nthreads);
+    }
+
+  }  /* All threads join master thread and disband */
+
+}