-}/* end_of_multiplication */
-
-/*** Function: gather ***/
-
-static void gather(){
-
-}/* end_of_gather */
-
-/*** Function: Display Matrix ***/
-
-static void display(matrix_t X){
-
-int i,j,t=0;
-
- printf(" ");
- for(j=0;j<X.cols;j++)
- printf("%.3d ",j);
- printf("\n");
- printf(" __");
- for(j=0;j<X.cols;j++)
- printf("____");
- printf("_\n");
-
- for(i=0;i<X.rows;i++){
- printf("%.3d | ",i);
- for(j=0;j<X.cols;j++)
- printf("%.3g ",X.data[t++]);
- printf("|\n");
- }
- printf(" --");
- for(j=0;j<X.cols;j++)
- printf("----");
- printf("-\n");
-
-}/* end_of_display */
-
-int master (int argc,char *argv[]) {
-
-xbt_ex_t e;
-
-int i,port,ask_result,step;
-
-matrix_t A,B,C;
-result_t result;
-
-gras_socket_t from;
-
- /* Init the GRAS's infrastructure */
- gras_init(&argc, argv);
-
- gras_socket_t socket[MATRIX_SIZE*MATRIX_SIZE]; /* sockets for brodcast to other slave */
-
- /* Initialize Matrixs */
-
- A.rows=A.cols=MATRIX_SIZE;
- B.rows=B.cols=MATRIX_SIZE;
- C.rows=C.cols=MATRIX_SIZE;
-
- A.data=xbt_malloc0(sizeof(double)*MATRIX_SIZE*MATRIX_SIZE);
- B.data=xbt_malloc0(sizeof(double)*MATRIX_SIZE*MATRIX_SIZE);
- C.data=xbt_malloc0(sizeof(double)*MATRIX_SIZE*MATRIX_SIZE);
-
- initmatrix(&A);
- initmatrix(&B);
-
- /* Get arguments and create sockets */
- port=atoi(argv[1]);
- //scatter();
- //scatter_parl();
- //multiplication();
- //gather();
- //display(A);
- /****************************** Init Data Send *********************************/
- int step_ack,j=0;
- init_data_t mydata;
- gras_os_sleep(60); // MODIFIER LES TEMPS D'ATTENTE 60 c trop normalement
- for( i=2;i< argc;i+=3){
- TRY {
- socket[j]=gras_socket_client(argv[i],port);
- } CATCH(e) {
- RETHROW0("Unable to connect to the server: %s");
- }
- INFO2("Connected to %s:%d.",argv[i],port);
-
- mydata.myrow=atoi(argv[i+1]); // My row
- mydata.mycol=atoi(argv[i+2]); // My column
-
- mydata.a=A.data[(mydata.myrow-1)*MATRIX_SIZE+(mydata.mycol-1)];
- mydata.b=B.data[(mydata.myrow-1)*MATRIX_SIZE+(mydata.mycol-1)];;
-
- gras_msg_send(socket[j],gras_msgtype_by_name("init_data"),&mydata);
- INFO3("Send Init Data to %s : data A= %.3g & data B= %.3g",gras_socket_peer_name(socket[j]),mydata.a,mydata.b);
- j++;
- } // end init Data Send
-
- /******************************* multiplication ********************************/
- INFO0("begin Multiplication");
-
- for (step=1; step <= MATRIX_SIZE; step++){
- gras_os_sleep(50);
- for (i=0; i< SLAVE_COUNT; i++){
- TRY {
- gras_msg_send(socket[i], gras_msgtype_by_name("step"), &step); /* initialize Mycol, MyRow, mydataA,mydataB*/
- } CATCH(e) {
- gras_socket_close(socket[i]);
- RETHROW0("Unable to send the msg : %s");
- }
- }
- INFO1("send to slave to begin a %d th step",step);
- /* wait for computing and slave messages exchange */
- i=0;
-
- while ( i< SLAVE_COUNT){
- TRY {
- gras_msg_wait(1300,gras_msgtype_by_name("step_ack"),&from,&step_ack);
- } CATCH(e) {
- RETHROW0("I Can't get a Ack step message from slave : %s");
- }
- i++;
- INFO3("Receive Ack step ack from %s (got %d of %d)",
- gras_socket_peer_name(from),
- i, SLAVE_COUNT);
- }
- }
- /********************************* gather ***************************************/
-
- ask_result=0;
- for( i=1;i< argc;i++){
- gras_msg_send(socket[i],gras_msgtype_by_name("ask_result"),&ask_result);
- INFO1("Send (Ask Result) message to %s",gras_socket_peer_name(socket[i]));
- }
- /* wait for results */
- for( i=1;i< argc;i++){
- gras_msg_wait(600,gras_msgtype_by_name("result"),&from,&result);
- C.data[(result.i-1)*MATRIX_SIZE+(result.j-1)]=result.value;
- }
- /* end of gather */
- INFO0 ("The Result of Multiplication is :");
- display(C);
-
-return 0;
-} /* end_of_master */