00001 #ifndef _HOCKNEY_P2P_MODEL_HPP
00002 #define _HOCKNEY_P2P_MODEL_HPP
00003
00004 #include <boost/serialization/access.hpp>
00005 #include <gsl/gsl_fit.h>
00006
00008 class hockney_p2p_model {
00009 private:
00010 friend class boost::serialization::access;
00011 double alpha;
00012 double beta;
00013
00014 public:
00015 hockney_p2p_model(double _alpha, double _beta) : alpha(_alpha), beta(_beta) {}
00016 hockney_p2p_model() : alpha(0.), beta(0.) {}
00017
00019 template <class Archive> void serialize(Archive & ar, const unsigned int version) {
00020 ar & alpha;
00021 ar & beta;
00022 }
00023
00025 void estimate(MPI_Comm comm, MPIB_msgset msgset, MPIB_precision precision, int i, int j) {
00026 int rank;
00027 MPI_Comm_rank(comm, &rank);
00028 if ((rank == i) || (rank == j)) {
00029 int count = 0;
00030 double* M = NULL ;
00031 double* T = NULL;
00032 MPIB_result result;
00033 int m;
00034
00035 count = (msgset.max_size - msgset.min_size)/msgset.stride;
00036 if ((msgset.max_size - msgset.min_size) % msgset.stride > 0 ) count++ ;
00037
00038
00039 if (rank == i) {
00040 M = (double *) malloc ( count * sizeof(double) );
00041 T = (double *) malloc ( count * sizeof(double) );
00042 }
00043 count = 0;
00044 for (m = msgset.min_size; m < msgset.max_size; m += msgset.stride) {
00045 MPIB_measure_p2p(MPI_Send, MPI_Recv, comm, i, j, m, precision, &result);
00046 if (rank == i) {
00047 M[count] = m;
00048
00049 T[count] = result.T / 2.;
00050 }
00051 count++;
00052 }
00053 if (rank == i) {
00054 double cov00, cov01, cov11, sumsq;
00055 gsl_fit_linear(M, 1, T, 1, count, &alpha, &beta, &cov00, &cov01, &cov11, &sumsq);
00056 free(M);
00057 free(T);
00058 }
00059 }
00060 }
00061
00063 void write_header(ostream &os){
00064 os << "#p2p:\ta\t\tb\n";
00065 }
00067 void write_elem(int i, int j, ostream &os) {
00068 os << "#" << i <<"-" << j <<":\t" << alpha << "\t" << beta << "\n";
00069 }
00071 void write_footer(ostream &os) {
00072 }
00073 };
00074
00075 #endif