start testing allreduce

This commit is contained in:
tqchen
2014-11-22 22:55:43 -08:00
parent cb1c34aef0
commit c499dd0f0c
4 changed files with 196 additions and 35 deletions

View File

@@ -11,19 +11,24 @@ else
endif
# specify tensor path
BIN = test_group_data test_quantile test_sock
BIN = test_group_data test_quantile test_allreduce
OBJ = sync_tcp.o
.PHONY: clean all
all: $(BIN) $(MPIBIN)
sync_tcp.o: ../src/sync/sync_tcp.cpp ../src/utils/*.h
test_group_data: test_group_data.cpp ../src/utils/*.h
test_quantile: test_quantile.cpp ../src/utils/*.h
test_sock: test_sock.cpp ../src/utils/*.h
test_allreduce: test_allreduce.cpp ../src/utils/*.h ../src/sync/sync.h sync_tcp.o
$(BIN) :
$(CXX) $(CFLAGS) $(LDFLAGS) -o $@ $(filter %.cpp %.o %.c, $^)
$(OBJ) :
$(CXX) -c $(CFLAGS) -o $@ $(firstword $(filter %.cpp %.c, $^) )
$(MPIBIN) :
$(MPICXX) $(CFLAGS) $(LDFLAGS) -o $@ $(filter %.cpp %.o %.c, $^)

22
test/test_allreduce.cpp Normal file
View File

@@ -0,0 +1,22 @@
#include <sync/sync.h>
using namespace xgboost;
int main(int argc, char *argv[]) {
sync::Init(argc, argv);
int rank = sync::GetRank();
std::string name = sync::GetProcessorName().c_str();
printf("start %s rank=%d\n", name.c_str(), rank);
std::vector<float> ndata(16);
for (size_t i = 0; i < ndata.size(); ++i) {
ndata[i] = i + rank;
}
sync::AllReduce(&ndata[0], ndata.size(), sync::kMax);
sync::Finalize();
for (size_t i = 0; i < ndata.size(); ++i) {
printf("%lu: %f\n", i, ndata[i]);
}
printf("all end\n");
return 0;
}