-}/* 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 maestro (int argc,char *argv[]) {
-
-xbt_ex_t e;
-int i,ask_result,step;
-result_t result;
-matrix_t A,B,C;
-gras_socket_t from;
-result_t result;
-
- gras_socket_t socket[MATRIX_SIZE*MATRIX_SIZE]; /* sockets for brodcast to other sensor */
-
-
- /* 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);
-
- /* Init the GRAS's infrastructure */
- gras_init(&argc, argv);
- /* Get arguments and create sockets */
- port=atoi(argv[1]);
- //scatter();multiplication();gather();
- //scatter_parl();
- /****************************** Init Data Send *********************************/
- int j=0;
- init_data_t mydata;
- 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=argv[i+1]; // My rank of row
- mydata.mycol=argv[i+2]; // My rank of 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);
- j++;
- } // end init Data Send
-
- /******************************* multiplication ********************************/
-
- for (step=1; step <= MATRIX_SIZE; step++){
- for (i=0; i< nbr_sensor; i++){
- TRY {
- gras_msg_send(socket[i], gras_msgtype_by_name("step"), &step); /* initialize Mycol, MyRow, mydataA,mydataB*/
-
- myrow,mycol,mydataA,mydataB
- } CATCH(e) {
- gras_socket_close(socket[i]);
- RETHROW0("Unable to send the msg : %s");
- }
- }
- INFO0("send to sensor to begin a next step");
- /* wait for computing and sensor messages exchange */
- i=0;
- while ( i< nbr_sensor){
- TRY {
- gras_msg_wait(600,gras_msgtype_by_name("step_ack"),&from,&mydata);
- } CATCH(e) {
- RETHROW0("I Can't get a init Data message from Maestro : %s");
- }
-
- i++;
- INFO1("Recive step ack from %s",gras_socket_peer_name(from));
- }
-
- }
- /********************************* gather ***************************************/
-
- int ask_result=0;
- for( i=1;i< argc;i++){
- gras_msg_send(socket[i],gras_msgtype_by_name("ask_result"),&ask_result);
- }
- /* 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 */
- display(C);
-
-return 0;
-} /* end_of_maestro */