File tree Expand file tree Collapse file tree 4 files changed +53
-41
lines changed Expand file tree Collapse file tree 4 files changed +53
-41
lines changed Original file line number Diff line number Diff line change 1
- CC = clang
2
- CXX = clang++
1
+ CC = mpicc
2
+ CXX = mpicxx
3
3
LDLIBS = -lpng
4
- CFLAGS = -lm -O3 -ffast-math -msse2
5
- hw2a : CFLAGS += -pthread
6
- hw2b : CC = mpicc
7
- hw2b : CXX = mpicxx
4
+ CFLAGS = -lm -O3 -pthread
5
+ hw2a : -march=native
6
+ hw2a : CC=clang
7
+ hw2a : CXX=clang++
8
+ hw2a : CFLAGS += -ffast-math
9
+ hw2b : -cc=clang
10
+ hw2b : -cxx=clang++
11
+ hw2b : -march=athlon64
12
+ hw2b : CFLAGS += -ffast-math -fno-associative-math
8
13
hw2b : CFLAGS += -fopenmp
9
14
CXXFLAGS = $(CFLAGS )
10
- TARGETS = hw2a
15
+ TARGETS = hw2a hw2b
11
16
12
17
.PHONY : all
13
18
all : $(TARGETS )
Original file line number Diff line number Diff line change 1
1
#include < iostream>
2
- #include < pthread.h>
3
2
#include < emmintrin.h>
4
- #include < time .h>
3
+ #include < mpi .h>
5
4
6
5
using namespace std ;
7
6
8
7
int main (int argc, char ** argv) {
9
- __m128d x, y, z;
10
- clock_t start, End;
11
- double a = 100 ;
12
- double b = 200 ;
13
- y[0 ] = 100 ;
14
- y[1 ] = 200 ;
15
- x[0 ] = 0 ;
16
- x[1 ] = 0 ;
17
- z[0 ] = 500 ;
18
- z[1 ] = 600 ;
8
+ MPI_Init (&argc, &argv);
9
+ // mpi argument
10
+ int rank, size;
11
+ MPI_Comm_rank (MPI_COMM_WORLD, &rank);
12
+ MPI_Comm_size (MPI_COMM_WORLD, &size);
13
+ double a = 2 ;
14
+ __m128d a_sse;
15
+ __m128d five;
16
+ __m128d two;
19
17
20
- start = clock ();
21
- for (int i = 0 ; i < 100000000 ; i++) {
22
- x = y + z;
18
+ double checkpoint;
19
+ double x, y;
20
+
21
+ a_sse[0 ] = a_sse[1 ] = 2 ;
22
+ five[0 ] = five[1 ] = 5 ;
23
+ two[0 ] = two[1 ] = 2 ;
24
+ checkpoint = MPI_Wtime ();
25
+ for (unsigned long long i = 0 ; i < 10000000000000 ; i++) {
26
+ a = 2 * a / 5 ;
23
27
}
24
- End = clock () ;
28
+ x = MPI_Wtime () - checkpoint ;
25
29
26
- cout << " assign cost time = " << End - start << endl;
27
- cout << x[0 ] << ' ' << x[1 ] << endl;
28
30
29
- x[0 ] = 0 ;
30
- x[1 ] = 0 ;
31
- y[0 ] = 100 ;
32
- y[1 ] = 200 ;
33
- z[0 ] = 500 ;
34
- z[1 ] = 600 ;
35
-
36
- start = clock ();
37
- for (int i = 0 ; i < 100000000 ; i++) {
38
- x = _mm_add_pd (y, z);
31
+ checkpoint = MPI_Wtime ();
32
+ for (unsigned long long i = 0 ; i < 10000000000000 ; i++) {
33
+ a_sse = _mm_mul_pd (two, _mm_mul_pd (five, a_sse));
39
34
}
40
- End = clock () ;
35
+ y = MPI_Wtime () - checkpoint ;
41
36
42
- cout << " mm_set cost time = " << End - start << endl;
43
- cout << x[ 0 ] << ' ' << x[ 1 ] << endl;
37
+ cout << " general variable cost time: " << x << endl;
38
+ cout << " vectorization calculation cost time: " << y << endl;
44
39
45
40
return 0 ;
46
41
}
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ mpicxx -lm -O3 -lpng test.cpp -o test
4
+ srun -n1 ./test
5
+ rm test
Original file line number Diff line number Diff line change 1
1
CC = mpicc
2
2
CXX = mpicxx
3
3
LDLIBS = -lpng
4
- CFLAGS = -lm -O3 -march=athlon64 -ffast-math -fno-associative-math -pthread
5
- hw2b : -cxx=clang++
4
+ CFLAGS = -lm -O3 -pthread
5
+ hw2a : -march=native
6
+ hw2a : CC=clang
7
+ hw2a : CXX=clang++
8
+ hw2a : CFLAGS += -ffast-math
6
9
hw2b : -cc=clang
10
+ hw2b : -cxx=clang++
11
+ hw2b : -march=athlon64
12
+ hw2b : CFLAGS += -ffast-math -fno-associative-math
7
13
hw2b : CFLAGS += -fopenmp
8
14
CXXFLAGS = $(CFLAGS )
9
- TARGETS = hw2b
15
+ TARGETS = hw2a hw2b
10
16
11
17
.PHONY : all
12
18
all : $(TARGETS )
13
19
14
20
.PHONY : clean
15
21
clean :
16
22
rm -f $(TARGETS ) $(TARGETS:=.o )
23
+
You can’t perform that action at this time.
0 commit comments