Commit d16e606f authored by Camille Coti's avatar Camille Coti
Browse files

Overlap computation + communication

parent 803648b5
...@@ -38,12 +38,16 @@ gi::ex add_expressions_parall( std::vector<std::string> expressions, gi::lst sym ...@@ -38,12 +38,16 @@ gi::ex add_expressions_parall( std::vector<std::string> expressions, gi::lst sym
int rank, size; int rank, size;
int chunk, end; int chunk, end;
char* expr_c; char* expr_c;
char* expr_2;
char* tmp;
char* total_c = NULL; char* total_c = NULL;
int expr = 0; int expr = 0;
int* m_len; int* m_len;
int* m_disp; int* m_disp;
char* toto = NULL; char* toto = NULL;
int totallen = 0; int totallen = 0;
MPI_Request req;
MPI_Status stat;
MPI_Comm_rank( comm, &rank ); MPI_Comm_rank( comm, &rank );
MPI_Comm_size( comm, &size ); MPI_Comm_size( comm, &size );
...@@ -158,6 +162,7 @@ gi::ex add_expressions_parall( std::vector<std::string> expressions, gi::lst sym ...@@ -158,6 +162,7 @@ gi::ex add_expressions_parall( std::vector<std::string> expressions, gi::lst sym
maxlen = ( maxlen < lengths[ expr ] ) ? lengths[ expr ] : maxlen; //std::max( maxlen, lengths[ expr ] ); maxlen = ( maxlen < lengths[ expr ] ) ? lengths[ expr ] : maxlen; //std::max( maxlen, lengths[ expr ] );
} }
expr_c = (char*)malloc( maxlen + 1 ); // Add a final \0 expr_c = (char*)malloc( maxlen + 1 ); // Add a final \0
expr_2 = (char*)malloc( maxlen + 1 ); // Add a final \0
/* Send the expressions */ /* Send the expressions */
...@@ -173,12 +178,27 @@ gi::ex add_expressions_parall( std::vector<std::string> expressions, gi::lst sym ...@@ -173,12 +178,27 @@ gi::ex add_expressions_parall( std::vector<std::string> expressions, gi::lst sym
if( 0 == rank ) toto = const_cast<char*>( expressions[expr].c_str() ); if( 0 == rank ) toto = const_cast<char*>( expressions[expr].c_str() );
MPI_Scatterv( toto, m_len, m_disp, MPI_CHAR, MPI_Iscatterv( toto, m_len, m_disp, MPI_CHAR,
expr_c, len, MPI_CHAR, expr_c, len, MPI_CHAR,
0, comm ); 0, comm , &req );
expr_c[len ] = '\0'; // The master sends C++ strings, which do not contain the final '\0' // results_s.push_back( std::string( expr_c ) );
results_s.push_back( std::string( expr_c ) );
if( 0 != expr ) {
Tens += de_linearize_expression( std::string( expr_2 ), symbols );
}
/* get the new expression in expr_c and swap the pointers so that we can work with expr_2 and receive in expr_c */
MPI_Wait( &req, &stat );
expr_c[len ] = '\0'; // The master sends C++ strings, which do not contain the final '\0'
// std::cout << "Got iteration " << expr << std::endl;
tmp = expr_2;
expr_2 = expr_c;
expr_c = tmp;
}
Tens += de_linearize_expression( std::string( expr_2 ), symbols );
// }
// if( rank == 0 ){ // if( rank == 0 ){
// for( peer = 0 ; peer < size ; peer++ ) { // for( peer = 0 ; peer < size ; peer++ ) {
// std::cout << "==" << toto[ m_disp[peer] ] << toto[ m_disp[peer] +1] << toto[ m_disp[peer] +2] << toto[ m_disp[peer] +3] << toto[ m_disp[peer] +4] << std::endl; // std::cout << "==" << toto[ m_disp[peer] ] << toto[ m_disp[peer] +1] << toto[ m_disp[peer] +2] << toto[ m_disp[peer] +3] << toto[ m_disp[peer] +4] << std::endl;
...@@ -188,11 +208,11 @@ gi::ex add_expressions_parall( std::vector<std::string> expressions, gi::lst sym ...@@ -188,11 +208,11 @@ gi::ex add_expressions_parall( std::vector<std::string> expressions, gi::lst sym
// std::cout << expr_c << std::endl; // std::cout << expr_c << std::endl;
/* TODO: this can be overlapped with the computation of the previous addition */ /* TODO: this can be overlapped with the computation of the previous addition */
} // }
/* Add them */ /* Add them */
Tens = add_expressions( results_s, symbols ); // Tens = add_expressions( results_s, symbols );
// std::cout << Tens << std::endl; // std::cout << Tens << std::endl;
/* Send the result to the master */ /* Send the result to the master */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment