diff --git a/Makefile b/Makefile index a359f0ac097d11cb4e7dce5dee370fcad636f4e6..e23dae41dc2f29404d97b777abe7aff9af9b81ad 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ CFLAGS = -g -O3 -Wno-unused-variable LDOPT = -lginac MPIEXEC = mpiexec -NP= 4 +NP = 5 all: tensormatrix_mpi diff --git a/tensormatrix_mpi.cpp b/tensormatrix_mpi.cpp index c16fc36104e9a60a4620f412b664f3009b5509c7..d6f0fafb068333630caf440dcbf17460b738830d 100644 --- a/tensormatrix_mpi.cpp +++ b/tensormatrix_mpi.cpp @@ -10,7 +10,9 @@ #define DEBUG 0 -#define N 4 // TODO passer ça en argument de la ligne de commande +#define DEFAULTN 4 /* Default size */ +#define DEFAULTFUNCTION 'm' /* Default function to use */ +#define NBFOREMEN 2 /* Default number of foremen to use with the hierarchical M/W */ #define TAG_PULL 0 /* W -> M initial */ #define TAG_WORK 1 /* M -> W here is some work */ @@ -23,7 +25,6 @@ #define TAG_END 7 /* M -> W we are done */ #define ROOT 0 -#define NBFOREMEN 2 #define MAXRESULT 8 @@ -33,6 +34,15 @@ namespace gi = GiNaC; libginac-dev ginac-tools mpic++ -O3 -g -Wall -o tensormatrix_mpi tensormatrix_mpi.cpp -lginac -Wno-unused-variable */ + +/* Arguments: + tensormatrix_mpi [N] [Function name] [Nb of foremen] + Function names being: + - M/m: Master-Worker -> multiply_1level_mw + - A/a: Master-Worker, addition on a slave -> multiply_1level_mw_addslave + - H/h: Hierarchical master-worker -> multiply_1level_mw_hierarch +*/ + /* Sequentiel sur Minimum real 3m31,034s */ @@ -64,9 +74,15 @@ public: parameters_2_t( void ){}; }; +/******************************************************************************* + * Global variables * + *******************************************************************************/ + MPI_Datatype DT_PARAMETERS; MPI_Datatype DT_PARAMETERS_2; +int nbforemen; /* Number of foremen to use with the hierarchical M/W */ + /******************************************************************************* * Prototypes * *******************************************************************************/ @@ -99,6 +115,7 @@ std::string linearize_expression( gi::ex ); gi::ex de_linearize_expression( std::string, gi::lst ); double getTime( void ); +void help( void ); /******************************************************************************* * Main function * @@ -108,6 +125,8 @@ int main( int argc, char** argv ){ tensor3D_t T; matrix_int_t J; + int N = DEFAULTN; + char tostart = DEFAULTFUNCTION; gi::ex Tpara = 0; gi::ex Tseq = 0; @@ -119,6 +138,39 @@ int main( int argc, char** argv ){ MPI_Comm_rank( MPI_COMM_WORLD, &rank ); // std::cout << "Process " << rank << " has pid " << getpid() << std::endl; + /* Parse the command line */ + + if( argc >= 2 ) { + if( argv[1][0] == 'h' ) { + if( 0 == rank ) help(); + MPI_Finalize(); + return EXIT_SUCCESS; + } + N = atoi( argv[1] ); + if( argc >= 3 ) { + switch( argv[2][0] ) { + case 'M': + case 'm': + tostart = 'm'; + break; + case 'A': + case 'a': + tostart = 'a'; + break; + case 'H': + case 'h': + tostart = 'h'; + break; + default: + std::cout << "Wrong function name. Using " << tostart << std::endl; + break; + } + if( argc >= 4 ) { + nbforemen = atoi( argv[3]); + } + } + } + /* Initialize the tensor with symbolic values */ create_tensor_3D( T, N, N, N ); @@ -273,6 +325,16 @@ void load_expression( std::string filename, gi::ex& expression, std::string name expression = a.unarchive_ex( symbols, name.c_str() ); } +void help(){ + std::cout << "Arguments:" << std::endl; + std::cout << "(mpiexec .... ) ./tensormatrix_mpi [N] [Function name] [Nb of foremen] : run the program" << std::endl; + std::cout << "(mpiexec .... ) ./tensormatrix_mpi h : display help" << std::endl; + std::cout << "Function names being: " << std::endl; + std::cout << " - M/m: Master-Worker -> multiply_1level_mw" << std::endl; + std::cout << " - A/a: Master-Worker, addition on a slave -> multiply_1level_mw_addslave" << std::endl; + std::cout << " - H/h: Hierarchical master-worker -> multiply_1level_mw_hierarch" << std::endl; +} + /******************************************************************************* * Utilities for parallelism * *******************************************************************************/ @@ -693,7 +755,7 @@ gi::ex two_level1_product( tensor3D_t* T, matrix_int_t *J, gi::ex A, int size, i for( c1 = 0 ; c1 < size ; c1++ ){ for( c2 = 0 ; c2 < size ; c2++ ){ TABC = TABB * (*J)[a2][c2]; - Tens += two_level2_product( T, J, TABC, N, a3, b2, b3, c1, c2 ); + Tens += two_level2_product( T, J, TABC, size, a3, b2, b3, c1, c2 ); } } }