Skip to content

Commit ee8443a

Browse files
committed
minor fixes to c compability, c-test now works
1 parent ab02dcc commit ee8443a

File tree

8 files changed

+36
-43
lines changed

8 files changed

+36
-43
lines changed

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

include/phiprof.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
3535
#define GET_MACRO(_1,_2,NAME,...) NAME
3636
#define phiprof_assert(...) GET_MACRO(__VA_ARGS__, phiprof_assert2, phiprof_assert1)(__VA_ARGS__)
3737

38-
38+
int phiprof_initialize();
3939
int phiprof_initializeTimer(char *label,int nGroups, ... );
40-
int phiprof_getId(char *label);
40+
int phiprof_getChildId(char *label);
4141

4242
int phiprof_start(char *label);
4343
int phiprof_stop(char *label);
@@ -46,7 +46,7 @@ int phiprof_startId(int id);
4646
int phiprof_stopId(int id);
4747
int phiprof_stopIdUnits(int id,double units,char *unitName);
4848

49-
int phiprof_print(MPI_Comm comm, char *fileNamePrefix, double minFraction);
49+
int phiprof_print(MPI_Comm comm, char *fileNamePrefix);
5050

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

include/phiprof.hpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,19 @@ namespace phiprof
6868
*/
6969
int initializeTimer(const std::string &label,const std::vector<std::string> &groups);
7070
/**
71-
* \overload int phiprof::initializeTimer(const std::string &label,const std::vector<std::string> &groups);
71+
* \overload int phiprof::initializeTimer(const std::string &label,const std::vector<std::string> &groups)
7272
*/
7373
int initializeTimer(const std::string &label);
7474
/**
75-
* \overload int phiprof::initializeTimer(const std::string &label,const std::vector<std::string> &groups);
75+
* \overload int phiprof::initializeTimer(const std::string &label,const std::vector<std::string> &groups)
7676
*/
7777
int initializeTimer(const std::string &label,const std::string &group1);
7878
/**
79-
* \overload int phiprof::initializeTimer(const std::string &label,const std::vector<std::string> &groups);
79+
* \overload int phiprof::initializeTimer(const std::string &label,const std::vector<std::string> &groups)
8080
*/
8181
int initializeTimer(const std::string &label,const std::string &group1,const std::string &group2);
8282
/**
83-
* \overload int phiprof::initializeTimer(const std::string &label,const std::vector<std::string> &groups);
83+
* \overload int phiprof::initializeTimer(const std::string &label,const std::vector<std::string> &groups)
8484
*/
8585
int initializeTimer(const std::string &label,const std::string &group1,const std::string &group2,const std::string &group3);
8686

@@ -92,7 +92,7 @@ namespace phiprof
9292
* @return
9393
* The id of the timer. -1 if it does not exist.
9494
*/
95-
int getId(const std::string &label);
95+
int getChildId(const std::string &label);
9696

9797
/**
9898
* Start a profiling timer.
@@ -177,12 +177,6 @@ namespace phiprof
177177
*/
178178
bool print(MPI_Comm comm, std::string fileNamePrefix="profile");
179179

180-
181-
182-
183-
184-
185-
186180
/**
187181
* Assert function
188182
*

src/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# source files.
2-
SRC = prettyprinttable.cpp timerdata.cpp timertree.cpp paralleltimertree.cpp phiprof.cpp #phiprof_c.cpp
2+
SRC = prettyprinttable.cpp timerdata.cpp timertree.cpp paralleltimertree.cpp phiprof.cpp phiprof_c.cpp
33
SRC_NO = nophiprof.cpp phiprof_c.cpp
44
OBJ = $(SRC:.cpp=.o)
55
OBJ_NO = $(SRC_NO:.cpp=.o)
@@ -16,7 +16,7 @@ INCLUDES = -I../include
1616
CLOCK_ID = CLOCK_MONOTONIC
1717

1818
# C++ compiler flags
19-
CCFLAGS = -O3 -fopenmp -std=c++11 -DCLOCK_ID=$(CLOCK_ID) #-DDEBUG_PHIPROF_TIMERS # -W -Wall -Wextra -pedantic
19+
CCFLAGS = -fpic -O3 -fopenmp -std=c++11 -DCLOCK_ID=$(CLOCK_ID) #-DDEBUG_PHIPROF_TIMERS # -W -Wall -Wextra -pedantic
2020

2121
# compiler
2222
CCC = CC

src/phiprof_c.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
2626

2727
using namespace std;
2828

29+
extern "C" int phiprof_initialize(){
30+
return (int)phiprof::initialize();
31+
32+
}
33+
2934
extern "C" int phiprof_initializeTimer(char *label,int nGroups, ... ){
3035
va_list listPointer;
3136
vector<string> groupStrings;
@@ -41,8 +46,8 @@ extern "C" int phiprof_initializeTimer(char *label,int nGroups, ... ){
4146

4247
}
4348

44-
extern "C" int phiprof_getId(char *label){
45-
return phiprof::getId(string(label));
49+
extern "C" int phiprof_getChildId(char *label){
50+
return phiprof::getChildId(string(label));
4651
}
4752

4853

src/timertree.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
2222
#include <string>
2323
#include <limits>
2424
#include <algorithm>
25-
#include <omp.h>
2625
#include <iostream>
2726

27+
#ifdef _OPENMP
28+
#include <omp.h>
29+
#endif
30+
2831
#include "timerdata.hpp"
2932
#include "timertree.hpp"
3033
#include "common.hpp"

src/timertree.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
2222
#define TIMERTREE_H
2323
#include <vector>
2424
#include "timerdata.hpp"
25-
25+
#ifdef _OPENMP
26+
#include <omp.h>
27+
#endif
2628

2729
class TimerTree {
2830
public:
@@ -65,8 +67,7 @@ class TimerTree {
6567
std::vector<int> childIds = timers[currentId[thread]].getChildIds();
6668
if ( std::find(childIds.begin(), childIds.end(), id) == childIds.end() ) {
6769
#pragma omp critical
68-
std::cerr << "PHIPROF-ERROR for thread "<< thread<< " omp_get_thread_num "<<
69-
omp_get_thread_num() << ": id "<< id <<
70+
std::cerr << "PHIPROF-ERROR for thread "<< thread<< ": id "<< id <<
7071
" is invalid, timer is not child of current timer "<< currentId[thread] <<
7172
":" << timers[currentId[thread]].getLabel() << std::endl;
7273
return false;

0 commit comments

Comments
 (0)