add speed test
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
export CC = gcc
|
||||
export CXX = g++
|
||||
export MPICXX = mpicxx
|
||||
export LDFLAGS= -pthread -lm
|
||||
export LDFLAGS= -pthread -lm -lrt
|
||||
export CFLAGS = -Wall -O3 -msse2 -Wno-unknown-pragmas -fPIC -I../src
|
||||
|
||||
# specify tensor path
|
||||
BIN = test_allreduce test_recover test_model_recover
|
||||
BIN = test_allreduce test_recover test_model_recover speed_test
|
||||
# objectives that makes up rabit library
|
||||
RABIT_OBJ = allreduce_base.o allreduce_robust.o engine.o
|
||||
MPIOBJ = engine_mpi.o
|
||||
|
||||
OBJ = $(RABIT_OBJ) test_allreduce.o test_recover.o test_model_recover.o
|
||||
MPIBIN = test_allreduce.mpi
|
||||
OBJ = $(RABIT_OBJ) test_allreduce.o test_recover.o test_model_recover.o speed_test.o
|
||||
MPIBIN = test_allreduce.mpi speed_test.mpi
|
||||
.PHONY: clean all
|
||||
|
||||
all: $(BIN) $(MPIBIN)
|
||||
@@ -21,23 +21,26 @@ engine.o: ../src/engine.cc ../src/*.h
|
||||
allreduce_robust.o: ../src/allreduce_robust.cc ../src/*.h
|
||||
engine_mpi.o: ../src/engine_mpi.cc
|
||||
test_allreduce.o: test_allreduce.cpp ../src/*.h
|
||||
speed_test.o: speed_test.cpp ../src/*.h
|
||||
test_recover.o: test_recover.cpp ../src/*.h
|
||||
test_model_recover.o: test_model_recover.cpp ../src/*.h
|
||||
|
||||
# we can link against MPI version to get use MPI
|
||||
test_allreduce: test_allreduce.o $(RABIT_OBJ)
|
||||
test_allreduce.mpi: test_allreduce.o $(MPIOBJ)
|
||||
speed_test: speed_test.o $(RABIT_OBJ)
|
||||
speed_test.mpi: speed_test.o $(MPIOBJ)
|
||||
test_recover: test_recover.o $(RABIT_OBJ)
|
||||
test_model_recover: test_model_recover.o $(RABIT_OBJ)
|
||||
|
||||
$(BIN) :
|
||||
$(CXX) $(CFLAGS) $(LDFLAGS) -o $@ $(filter %.cpp %.o %.c %.cc, $^)
|
||||
$(CXX) $(CFLAGS) -o $@ $(filter %.cpp %.o %.c %.cc, $^) $(LDFLAGS)
|
||||
|
||||
$(OBJ) :
|
||||
$(CXX) -c $(CFLAGS) -o $@ $(firstword $(filter %.cpp %.c %.cc, $^) )
|
||||
|
||||
$(MPIBIN) :
|
||||
$(MPICXX) $(CFLAGS) $(LDFLAGS) -o $@ $(filter %.cpp %.o %.c %.cc, $^)
|
||||
$(MPICXX) $(CFLAGS) -o $@ $(filter %.cpp %.o %.c %.cc, $^) $(LDFLAGS)
|
||||
|
||||
$(MPIOBJ) :
|
||||
$(MPICXX) -c $(CFLAGS) -o $@ $(firstword $(filter %.cpp %.c %.cc, $^) )
|
||||
|
||||
96
test/speed_test.cpp
Normal file
96
test/speed_test.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
#include <rabit.h>
|
||||
#include <utils.h>
|
||||
#include <timer.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cmath>
|
||||
#include <time.h>
|
||||
|
||||
using namespace rabit;
|
||||
|
||||
double max_tdiff, sum_tdiff, bcast_tdiff, tot_tdiff;
|
||||
|
||||
inline void TestMax(size_t n) {
|
||||
int rank = rabit::GetRank();
|
||||
//int nproc = rabit::GetWorldSize();
|
||||
|
||||
std::vector<float> ndata(n);
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
ndata[i] = (i * (rank+1)) % 111;
|
||||
}
|
||||
double tstart = utils::GetTime();
|
||||
rabit::Allreduce<op::Max>(&ndata[0], ndata.size());
|
||||
max_tdiff += utils::GetTime() - tstart;
|
||||
}
|
||||
|
||||
inline void TestSum(size_t n) {
|
||||
int rank = rabit::GetRank();
|
||||
//int nproc = rabit::GetWorldSize();
|
||||
const int z = 131;
|
||||
std::vector<float> ndata(n);
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
ndata[i] = (i * (rank+1)) % z;
|
||||
}
|
||||
double tstart = utils::GetTime();
|
||||
rabit::Allreduce<op::Sum>(&ndata[0], ndata.size());
|
||||
sum_tdiff += utils::GetTime() - tstart;
|
||||
}
|
||||
|
||||
inline void TestBcast(size_t n, int root) {
|
||||
int rank = rabit::GetRank();
|
||||
std::string s; s.resize(n);
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
s[i] = char(i % 126 + 1);
|
||||
}
|
||||
std::string res;
|
||||
if (root == rank) {
|
||||
res = s;
|
||||
}
|
||||
double tstart = utils::GetTime();
|
||||
rabit::Broadcast(&res, root);
|
||||
bcast_tdiff += utils::GetTime() - tstart;
|
||||
}
|
||||
|
||||
inline void PrintStats(const char *name, double tdiff) {
|
||||
int nproc = rabit::GetWorldSize();
|
||||
double tsum = tdiff;
|
||||
rabit::Allreduce<op::Sum>(&tsum, 1);
|
||||
double tavg = tsum / nproc;
|
||||
double tsqr = tdiff - tavg;
|
||||
tsqr *= tsqr;
|
||||
rabit::Allreduce<op::Sum>(&tsqr, 1);
|
||||
double tstd = sqrt(tsqr / nproc);
|
||||
if (rabit::GetRank() == 0) {
|
||||
utils::LogPrintf("%s: mean=%g, std=%g sec\n", name, tavg, tstd);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc < 3) {
|
||||
printf("Usage: <ndata> <nrepeat>\n");
|
||||
return 0;
|
||||
}
|
||||
srand(0);
|
||||
int n = atoi(argv[1]);
|
||||
int nrep = atoi(argv[2]);
|
||||
utils::Check(nrep >= 1, "need to at least repeat running once");
|
||||
rabit::Init(argc, argv);
|
||||
//int rank = rabit::GetRank();
|
||||
int nproc = rabit::GetWorldSize();
|
||||
std::string name = rabit::GetProcessorName();
|
||||
max_tdiff = sum_tdiff = bcast_tdiff = 0;
|
||||
double tstart = utils::GetTime();
|
||||
for (int i = 0; i < nrep; ++i) {
|
||||
TestMax(n);
|
||||
TestSum(n);
|
||||
TestBcast(n, rand() % nproc);
|
||||
}
|
||||
tot_tdiff = utils::GetTime() - tstart;
|
||||
// use allreduce to get the sum and std of time
|
||||
PrintStats("max_tdiff", max_tdiff);
|
||||
PrintStats("sum_tdiff", sum_tdiff);
|
||||
PrintStats("bcast_tdiff", bcast_tdiff);
|
||||
PrintStats("tot_tdiff", tot_tdiff);
|
||||
rabit::Finalize();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user