Browse Source

init

master
Robin Thoni 8 years ago
parent
commit
d19ddc36c0
6 changed files with 93 additions and 1 deletions
  1. 2
    1
      .gitignore
  2. 30
    0
      Makefile
  3. 37
    0
      common.c
  4. 12
    0
      common.h
  5. 6
    0
      d2p.c
  6. 6
    0
      d2s.c

+ 2
- 1
.gitignore View File

@@ -1,2 +1,3 @@
1
-omp-fusion-sort
1
+omp-fusion-sort-seq
2
+omp-fusion-sort-par
2 3
 *.o

+ 30
- 0
Makefile View File

@@ -0,0 +1,30 @@
1
+CFLAGS = -Wall -Wextra -Werror -pedantic -std=c99 -fopenmp
2
+LDLIBS = -lrt
3
+CC = gcc
4
+SOURCES_COMMON = common.c
5
+SOURCES_SEQ = $(SOURCES_COMMON) d2s.c
6
+OUT_SEQ = omp-fusion-sort-seq
7
+OBJS_SEQ = $(SOURCES_SEQ:.c=.o)
8
+SOURCES_PAR = $(SOURCES_COMMON) d2p.c
9
+OUT_PAR = omp-fusion-sort-par
10
+OBJS_PAR = $(SOURCES_PAR:.c=.o)
11
+
12
+all: release
13
+
14
+debug: CFLAGS += -g3 -ggdb3
15
+debug: $(OUT_SEQ) $(OUT_PAR)
16
+
17
+release: CFLAGS += -o3
18
+release: $(OUT_SEQ) $(OUT_PAR)
19
+
20
+$(OUT_SEQ): $(OBJS_SEQ)
21
+	  $(LINK.c) $(OUTPUT_OPTION) $(OBJS_SEQ) $(LDLIBS)
22
+
23
+$(OUT_PAR): $(OBJS_PAR)
24
+	  $(LINK.c) $(OUTPUT_OPTION) $(OBJS_PAR) $(LDLIBS)
25
+
26
+clean:
27
+	  rm -f *.o
28
+
29
+distclean: clean
30
+	  rm -f *.a $(OUT_SEQ) $(OUT_PAR)

+ 37
- 0
common.c View File

@@ -0,0 +1,37 @@
1
+#include "common.h"
2
+#include <stdio.h>
3
+
4
+struct timespec get_time()
5
+{
6
+    struct timespec start_time;
7
+    clock_gettime(CLOCK_MONOTONIC, &start_time);
8
+    return start_time;
9
+}
10
+
11
+struct timespec time_diff(struct timespec* ts1, struct timespec* ts2)
12
+{
13
+  static struct timespec ts;
14
+  ts.tv_sec = ts1->tv_sec - ts2->tv_sec;
15
+  ts.tv_nsec = ts1->tv_nsec - ts2->tv_nsec;
16
+  if (ts.tv_nsec < 0) {
17
+    ts.tv_sec--;
18
+    ts.tv_nsec += 1000000000;
19
+  }
20
+  return ts;
21
+}
22
+
23
+struct timespec get_duration(struct timespec* ts)
24
+{
25
+  struct timespec time = get_time();
26
+  return time_diff(&time, ts);
27
+}
28
+
29
+void print_time(struct timespec* ts)
30
+{
31
+  long ns = ts->tv_nsec % 1000;
32
+  long us = (ts->tv_nsec / 1000) % 1000;
33
+  long ms = (ts->tv_nsec / 1000000) % 1000;
34
+  long s =  (ts->tv_nsec / 1000000000) % 1000 + ts->tv_sec;
35
+  long t = (s * 1000000000) + (ms * 1000000) + (us * 1000) + ns;
36
+  printf("%3lds %3ldms %3ldus %3ldns %12ld", s, ms, us, ns, t);
37
+}

+ 12
- 0
common.h View File

@@ -0,0 +1,12 @@
1
+#ifndef COMMON_H
2
+#define COMMON_H
3
+
4
+#define _POSIX_C_SOURCE 199309L
5
+#include <time.h>
6
+
7
+struct timespec get_time();
8
+struct timespec time_diff(struct timespec* ts1, struct timespec* ts2);
9
+struct timespec get_duration(struct timespec* ts);
10
+void print_time(struct timespec* ts);
11
+
12
+#endif

+ 6
- 0
d2p.c View File

@@ -0,0 +1,6 @@
1
+#include "common.h"
2
+
3
+int main(void)
4
+{
5
+  return 0;
6
+}

+ 6
- 0
d2s.c View File

@@ -0,0 +1,6 @@
1
+#include "common.h"
2
+
3
+int main(void)
4
+{
5
+  return 0;
6
+}

Loading…
Cancel
Save