Skip to content

Commit a587423

Browse files
committed
feature: Makefile change
1 parent b5ffa76 commit a587423

File tree

4 files changed

+53
-41
lines changed

4 files changed

+53
-41
lines changed

hw2/hw2_a/v6/Makefile

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
CC = clang
2-
CXX = clang++
1+
CC = mpicc
2+
CXX = mpicxx
33
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
813
hw2b: CFLAGS += -fopenmp
914
CXXFLAGS = $(CFLAGS)
10-
TARGETS = hw2a
15+
TARGETS = hw2a hw2b
1116

1217
.PHONY: all
1318
all: $(TARGETS)

hw2/hw2_a/v6/test.cpp

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,41 @@
11
#include <iostream>
2-
#include <pthread.h>
32
#include <emmintrin.h>
4-
#include <time.h>
3+
#include <mpi.h>
54

65
using namespace std;
76

87
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;
1917

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;
2327
}
24-
End = clock();
28+
x = MPI_Wtime() - checkpoint;
2529

26-
cout << "assign cost time = " << End - start << endl;
27-
cout << x[0] << ' ' << x[1] << endl;
2830

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));
3934
}
40-
End = clock();
35+
y = MPI_Wtime() - checkpoint;
4136

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;
4439

4540
return 0;
4641
}

hw2/hw2_a/v6/test.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
mpicxx -lm -O3 -lpng test.cpp -o test
4+
srun -n1 ./test
5+
rm test

hw2/hw2_b/v1/Makefile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
CC = mpicc
22
CXX = mpicxx
33
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
69
hw2b: -cc=clang
10+
hw2b: -cxx=clang++
11+
hw2b: -march=athlon64
12+
hw2b: CFLAGS += -ffast-math -fno-associative-math
713
hw2b: CFLAGS += -fopenmp
814
CXXFLAGS = $(CFLAGS)
9-
TARGETS = hw2b
15+
TARGETS = hw2a hw2b
1016

1117
.PHONY: all
1218
all: $(TARGETS)
1319

1420
.PHONY: clean
1521
clean:
1622
rm -f $(TARGETS) $(TARGETS:=.o)
23+

0 commit comments

Comments
 (0)