Skip to content

Commit 89c4f99

Browse files
authored
Merge pull request #7 from fmihpc/improved-thread-support
Phiprof 2.0: Improved thread support
2 parents 98c7298 + ee8443a commit 89c4f99

22 files changed

+2340
-1513
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*.dat
2+
*.vlsv
3+
*.silo
4+
*.o
5+
version.cpp
6+
\#*\#
7+
*~
8+
nbproject
9+
vlasiator
10+
vlasiator+pat
11+
nbproject

README

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
Phiprof – Parallel Hierarchical Profiler
22

3-
Copyright (c) 2011,2012 Finnish Meteorological Institute
4-
Author: Sebastian von Alfthan (sebastian.von.alfthan at fmi.fi)
3+
Copyright (c) 2011 - 2015 Finnish Meteorological Institute
4+
Copyright (c) 2016 CSC - IT Center for Science
5+
6+
Licence: LGPL 3
7+
8+
Author: Sebastian von Alfthan (sebastian.von.alfthan at csc.fi)
9+
510

611
Phiprof a simple library that can be used to profile parallel MPI
7-
programs developed at the Finnish Meteorological Institute. It can be
8-
used to produce a hierarchical report of time (average, max, min)
9-
spent in different timer regions. A log format can also be written,
10-
where the performance as a function of time may be reported.
12+
programs developed originally at the Finnish Meteorological
13+
Institute. It can be used to produce a hierarchical report of time
14+
(average, max, min) spent in different timer regions. A log format can
15+
also be written, where the performance as a function of time may be
16+
reported.
1117

1218

1319
Features
1420
* Supports C++ and C (C programs have to be linked with a C++ compiler)
1521
* Low overhead (Less than 1 us)
1622
* Can print the total time as a human-readable hierarchical report
17-
* Can print the evolution of time metrics in a easy-to-parse format to track how the performance develops over time
1823
* Automatically handles cases where groups of processes execute different codepaths
19-
* (Cray specific) All timer regions are also defined as Craypat regions if Craypat module is loaded
2024

2125
Not supported
2226
* No Fortran interface
23-
* Phiprof is not threadsafe, it should only be called by the master thread, or outside of threaded regions.
2427
* Phiprof does not automatically add regions, these have to be added manually into the code.
2528

2629

example/c_test/Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ OBJ = $(SRC:.c=.o)
66
INCLUDES =
77

88
# C compiler flags (-g -O2 -Wall)
9-
CFLAGS = -O3 -I../../include
10-
LDFLAGS = -L../../lib -lphiprof
9+
CFLAGS = -O3 -I../../include -fopenmp
10+
LDFLAGS = -L../../lib -lphiprof -lgomp -ldl
1111
# compiler
12-
CCC = mpicc
12+
CCC = cc
1313
# linker (c++ compiler)
14-
LNK = mpiCC
14+
LNK = CC
1515

1616
.SUFFIXES: .c
1717

1818
default: $(OBJ)
19-
$(LNK) -o test $(OBJ) $(LDFLAGS)
19+
$(LNK) -o test $(OBJ) $(LDFLAGS)
2020

2121
.c.o:
2222
$(CCC) $(INCLUDES) $(CFLAGS) -c $< -o $@

example/c_test/test.c

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ int main(int argc,char **argv){
5656
if(rank==0)
5757
printf( "Measuring performance of start-stop calls\n");
5858

59+
phiprof_initialize();
5960

61+
6062
phiprof_start("Benchmarking phiprof");
6163
phiprof_start("Initalized timers using ID");
6264

@@ -97,33 +99,21 @@ int main(int argc,char **argv){
9799
phiprof_start("Test accuracy");
98100
if(rank==0)
99101
printf( " 1/2\n");
100-
phiprof_start("100 computations");
102+
phiprof_start("100 computations x 0.1s");
101103
for(i=0;i<100;i++){
102104
phiprof_start("compute");
103105
compute(0.1);
104106
phiprof_stop("compute");
105107
}
106-
phiprof_stop("100 computations");
108+
phiprof_stop("100 computations x 0.1s");
107109

108-
if(rank==0)
109-
printf( " 2/2\n" );
110-
MPI_Barrier(MPI_COMM_WORLD);
111-
phiprof_start("100 computations + logprofile");
112-
for(i=0;i<100;i++){
113-
phiprof_start("compute");
114-
compute(0.1);
115-
phiprof_printLogProfile(MPI_COMM_WORLD,i,"profile_log_alllev"," ",0);
116-
phiprof_printLogProfile(MPI_COMM_WORLD,i,"profile_log_maxlev1"," ",1);
117-
phiprof_stop("compute");
118-
}
119-
phiprof_stop("100 computations + logprofile");
120110

121111
phiprof_stop("Test accuracy");
122112

123113
MPI_Barrier(MPI_COMM_WORLD);
124114
double t1=MPI_Wtime();
125-
phiprof_print(MPI_COMM_WORLD,"profile_full",0.0);
126-
phiprof_print(MPI_COMM_WORLD,"profile_minfrac0.01",0.01);
115+
phiprof_print(MPI_COMM_WORLD,"profile");
116+
127117
if(rank==0)
128118
printf( "Print time is %g\n",MPI_Wtime()-t1);
129119

example/cpp_test/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ OBJ = $(SRC:.cpp=.o)
66
INCLUDES =
77

88
# C++ compiler flags (-g -O2 -Wall)
9-
CCFLAGS = -O3 -I../../include
10-
LDFLAGS = -L../../lib -lphiprof -lgomp
9+
CCFLAGS = -O3 -I../../include -fopenmp
10+
LDFLAGS = -L../../lib -lphiprof -lgomp -ldl
1111
# compiler
12-
CCC = mpiCC
12+
CCC = CC
1313

1414

1515
.SUFFIXES: .cpp
1616

1717
default: $(OBJ)
18-
$(CCC) -o test $(OBJ) $(LDFLAGS)
18+
$(CCC) -o test $(OBJ) $(LDFLAGS)
1919

2020
.cpp.o:
2121
$(CCC) $(INCLUDES) $(CCFLAGS) -c $< -o $@

example/cpp_test/test.cpp

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
License along with this library. If not, see <http://www.gnu.org/licenses/>.
1818
1919
*/
20-
21-
22-
#include "mpi.h"
2320
#include <iostream>
2421
#include <iomanip>
2522
#include <string>
2623
#include <vector>
24+
#include "mpi.h"
25+
#include "omp.h"
2726
#include "phiprof.hpp"
2827

2928
using namespace std;
@@ -58,9 +57,11 @@ int main(int argc,char **argv){
5857
const int nIterations=1000000;
5958
if(rank==0)
6059
cout << "Measuring performance of start-stop calls" <<endl;
61-
6260

63-
phiprof::start("Benchmarking phiprofr");
61+
phiprof::initialize();
62+
63+
phiprof::start("Benchmarking phiprof");
64+
6465
phiprof::start("Initalized timers using ID");
6566

6667
if(rank==0)
@@ -74,6 +75,7 @@ int main(int argc,char **argv){
7475

7576
if(rank==0)
7677
cout << " 2/3" <<endl;
78+
7779
phiprof::start("Re-initialized timers using ID");
7880
for(int i=0;i<nIterations;i++){
7981
id_a=phiprof::initializeTimer("a","A with ID");
@@ -89,44 +91,68 @@ int main(int argc,char **argv){
8991
phiprof::start("a");
9092
phiprof::stop("a");
9193
}
92-
phiprof::stop("Timers using labels",nIterations*2,"start-stop");
93-
phiprof::stop("Benchmarking phiprofr");
94+
phiprof::stop("Timers using labels", nIterations*2, "start-stop");
95+
phiprof::stop("Benchmarking phiprof");
9496

9597
MPI_Barrier(MPI_COMM_WORLD);
9698

9799
if(rank==0)
98100
cout << "Measuring accuracy" <<endl;
99-
/*
101+
102+
100103
phiprof::start("Test accuracy");
104+
101105
if(rank==0)
102-
cout << " 1/2" <<endl;
103-
phiprof::start("100x0.1s computations");
106+
cout << " 1/3" <<endl;
107+
phiprof::start("100x0.01s computations");
104108
for(int i=0;i<100;i++){
105109
phiprof::start("compute");
106-
compute(0.1);
110+
compute(0.01);
107111
phiprof::stop("compute");
108112
}
109-
phiprof::stop("100x0.1s computations");
113+
phiprof::stop("100x0.01s computations");
114+
115+
if(rank==0)
116+
cout << " 2/3" <<endl;
117+
MPI_Barrier(MPI_COMM_WORLD);
118+
119+
phiprof::start("100 x 0.01 (threadId + 1)s, ID");
120+
int id = phiprof::initializeTimer("compute");
121+
#pragma omp parallel
122+
for(int i=0;i<100;i++){
123+
phiprof::start(id);
124+
compute(0.01 * (omp_get_thread_num() + 1));
125+
phiprof::stop(id);
126+
}
127+
phiprof::stop("100 x 0.01 (threadId + 1)s, ID");
110128

111129
if(rank==0)
112-
cout << " 2/2" <<endl;
130+
cout << " 3/3" <<endl;
113131
MPI_Barrier(MPI_COMM_WORLD);
114-
phiprof::start("100x0.1s computations + logprofile");
132+
133+
phiprof::start("100 x 0.01 (threadId + 1)s, String");
134+
#pragma omp parallel
115135
for(int i=0;i<100;i++){
116136
phiprof::start("compute");
117-
compute(0.1);
118-
phiprof::printLogProfile(MPI_COMM_WORLD,i);
119-
phiprof::printLogProfile(MPI_COMM_WORLD,i,"profile_log_maxlev1"," ",1);
137+
compute(0.01 * (omp_get_thread_num() + 1));
120138
phiprof::stop("compute");
121139
}
122-
phiprof::stop("100x0.1s computations + logprofile");
140+
phiprof::stop("100 x 0.01 (threadId + 1)s, String");
141+
142+
123143

124144
phiprof::stop("Test accuracy");
125-
*/
145+
146+
if(rank%2 == 1) {
147+
148+
phiprof::start("Test-profile-groups");
149+
phiprof::stop("Test-profile-groups");
150+
}
151+
152+
126153
MPI_Barrier(MPI_COMM_WORLD);
127154
double t1=MPI_Wtime();
128155
phiprof::print(MPI_COMM_WORLD);
129-
phiprof::print(MPI_COMM_WORLD,"profile_minfrac0.01",0.01);
130156
if(rank==0)
131157
cout<< "Print time is "<<MPI_Wtime()-t1<<endl;
132158
// phiprof::print(MPI_COMM_WORLD,0.1);

include/phiprof.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/*
22
This file is part of the phiprof library
33
4-
Copyright 2010, 2011, 2012 Finnish Meteorological Institute
4+
Copyright 2012, 2013, 2014, 2015 Finnish Meteorological Institute
5+
Copyright 2015, 2016 CSC - IT Center for Science
56
67
Phiprof is free software: you can redistribute it and/or modify
78
it under the terms of the GNU Lesser General Public License as
@@ -34,9 +35,9 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
3435
#define GET_MACRO(_1,_2,NAME,...) NAME
3536
#define phiprof_assert(...) GET_MACRO(__VA_ARGS__, phiprof_assert2, phiprof_assert1)(__VA_ARGS__)
3637

37-
38+
int phiprof_initialize();
3839
int phiprof_initializeTimer(char *label,int nGroups, ... );
39-
int phiprof_getId(char *label);
40+
int phiprof_getChildId(char *label);
4041

4142
int phiprof_start(char *label);
4243
int phiprof_stop(char *label);
@@ -45,8 +46,7 @@ int phiprof_startId(int id);
4546
int phiprof_stopId(int id);
4647
int phiprof_stopIdUnits(int id,double units,char *unitName);
4748

48-
int phiprof_print(MPI_Comm comm, char *fileNamePrefix, double minFraction);
49-
int phiprof_printLogProfile(MPI_Comm comm, double simulationTime, char *fileNamePrefix, char *separator, int maxLevel);
49+
int phiprof_print(MPI_Comm comm, char *fileNamePrefix);
5050

5151
void phiprof_phiprofAssert(int condition, char* errorMessage, char* fileName, int line);
5252

0 commit comments

Comments
 (0)