Commit 803648b5 authored by Camille Coti's avatar Camille Coti
Browse files

bug fix

parent a744dd40
...@@ -77,27 +77,35 @@ gi::ex add_expressions_parall( std::vector<std::string> expressions, gi::lst sym ...@@ -77,27 +77,35 @@ gi::ex add_expressions_parall( std::vector<std::string> expressions, gi::lst sym
for( auto s: expressions ) { for( auto s: expressions ) {
chunk = ceil( s.length() / size ); chunk = ceil( s.length() / size );
end = 0;
for( peer = 0 ; peer < size ; peer++ ) { for( peer = 0 ; peer < size ; peer++ ) {
if( 0 == peer ) { if( 0 == peer ) {
displ[ expr ] = 0; displ[ peer * nb + expr] = 0;
end = chunk; end = chunk;
} else { } else {
displ[ peer * nb + expr] = end + 1;
end = displ[ peer * nb + expr] + chunk; end = displ[ peer * nb + expr] + chunk;
} }
/* How much are we going to send: stop at a + or - sign (and keep the sign) */ /* How much are we going to send: stop at a + or - sign (and keep the sign) */
while( !( s[end] == '+' || s[end] == '-' || end == (int)s.length() - 1) ){ while( ( end < (int)s.length() - 1) && !( s[end] == '+' || s[end] == '-' || end == (int)s.length() - 1 )) {
end++; end++;
} }
end--; end--;
// std::cout << s[end-4] << s[end-3] << s[end-2] << s[end-1] << s[end] << std::endl;
if( 0 == peer ) { if( 0 == peer ) {
lengths[ expr ] = end + 1; lengths[ expr ] = end + 1;
} else { } else {
// std::cout << "peer " << peer << " expr " << expr << " end " << end << std::endl; // std::cout << "peer " << peer << " expr " << expr << " end " << end << std::endl;
lengths[ peer * nb + expr ] = end - displ[ peer * nb + expr ] + 1; lengths[ peer * nb + expr ] = end - displ[ peer * nb + expr ] + 1;
} }
if( peer < size - 1 ) displ[ ( peer + 1 ) * nb + expr] = end; // if( peer < size - 1 ) displ[ ( peer + 1 ) * nb + expr] = end;
// std::cout << "Disp " << displ[ peer * nb + expr] << std::endl;
// std::cout << s << std::endl;
// std::cout << s[ displ[ peer * nb + expr] ] << s[ displ[ peer * nb + expr] + 1 ] << s[ displ[ peer * nb + expr] + 2 ] << s[ displ[ peer * nb + expr] + 3 ] << s[ displ[ peer * nb + expr] + 4 ] << std::endl;
} }
expr++; expr++;
...@@ -171,13 +179,22 @@ gi::ex add_expressions_parall( std::vector<std::string> expressions, gi::lst sym ...@@ -171,13 +179,22 @@ gi::ex add_expressions_parall( std::vector<std::string> expressions, gi::lst sym
expr_c[len ] = '\0'; // The master sends C++ strings, which do not contain the final '\0' 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( rank == 0 ){
// 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 << 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;
/* Send the result to the master */ /* Send the result to the master */
std::string expr_s = linearize_expression( Tens ); std::string expr_s = linearize_expression( Tens );
...@@ -187,28 +204,33 @@ gi::ex add_expressions_parall( std::vector<std::string> expressions, gi::lst sym ...@@ -187,28 +204,33 @@ gi::ex add_expressions_parall( std::vector<std::string> expressions, gi::lst sym
if( 0 == rank ) { if( 0 == rank ) {
for( peer = 0 ; peer < size ; peer++ ){ for( peer = 0 ; peer < size ; peer++ ){
m_disp[peer] = totallen; m_disp[peer] = totallen + 1;
totallen += m_len[peer]; totallen += m_len[peer];
} }
m_disp[0] = 0;
total_c = (char*) malloc( ( totallen + size ) * sizeof( char ) ); total_c = (char*) malloc( ( totallen + size ) * sizeof( char ) );
} }
// sleep( rank );
expr_c = const_cast<char*>( expr_s.c_str() ); expr_c = const_cast<char*>( expr_s.c_str() );
// std::cout << rank << " | " << expr_c << std::endl;
std::cout << expr_c[ len-5 ] << expr_c[ len-4 ] << expr_c[ len-3 ] << expr_c[ len-2 ] << expr_c[ len-1 ] << std::endl;
//std::cout << expr_s << std::endl;
// std::cout << expr_c[ len-5 ] << expr_c[ len-4 ] << expr_c[ len-3 ] << expr_c[ len-2 ] << expr_c[ len-1 ] << std::endl;
// std::cout << expr_c[ 0 ] << expr_c[ 1 ] << expr_c[ 2 ] << expr_c[ 3 ] << expr_c[ 4 ] << std::endl;
MPI_Gatherv( expr_c, len, MPI_CHAR, total_c, m_len, m_disp, MPI_CHAR, 0, comm ); MPI_Gatherv( expr_c, len, MPI_CHAR, total_c, m_len, m_disp, MPI_CHAR, 0, comm );
if( 0 == rank ){ /* replace the \n's by + */ if( 0 == rank ){ /* replace the \n's by + */
for( peer = 1 ; peer < size ; peer++ ){ for( peer = 1 ; peer < size ; peer++ ){
total_c[ m_disp[peer] ] = '+' ; total_c[ m_disp[peer] - 1 ] = '+' ;
} }
std::cout << total_c[ totallen-5 ] << total_c[ totallen-4 ] << total_c[ totallen-3 ] << total_c[ totallen-2 ] << total_c[ totallen-1 ] << std::endl; // std::cout << total_c[ totallen-5 ] << total_c[ totallen-4 ] << total_c[ totallen-3 ] << total_c[ totallen-2 ] << total_c[ totallen-1 ] << std::endl;
expr_c[ totallen + size - 1 ] = '\n' ; expr_c[ totallen + size - 1 ] = '\n' ;
// std::cout << total_c << std::endl; //x std::cout <<"Total: " << total_c << std::endl;
Tens = de_linearize_expression( std::string( total_c ), symbols ); // Tens = de_linearize_expression( std::string( total_c ), symbols );
} }
free( lengths ); free( lengths );
......
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