X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/520f4715694523f1ac80803a19267eaf5ac60f9d..cf57fb58889894670e2594d2e3b6a213d8fd6089:/examples/gras/mmrpc/mmrpc.c diff --git a/examples/gras/mmrpc/mmrpc.c b/examples/gras/mmrpc/mmrpc.c index fce8447332..8f8e88270e 100644 --- a/examples/gras/mmrpc/mmrpc.c +++ b/examples/gras/mmrpc/mmrpc.c @@ -1,212 +1,183 @@ -/* $Id$ */ - /* GridRPC - Fake Grid RPC thingy doing matrix multiplications (as expected)*/ -/* Copyright (c) 2005 Martin Quinson. All rights reserved. */ +/* Copyright (c) 2005, 2006, 2007, 2010. The SimGrid Team. + * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "gras.h" - -#define MATSIZE 128 - -XBT_LOG_NEW_DEFAULT_CATEGORY(MatMult,"Messages specific to this example"); - -GRAS_DEFINE_TYPE(s_matrix, -struct s_matrix { - int rows; - int cols; - double *ctn GRAS_ANNOTE(size, rows*cols); -};) -typedef struct s_matrix matrix_t; +#define GRAS_DEFINE_TYPE_EXTERN +#include "xbt/matrix.h" +#include "mmrpc.h" -static void mat_dump(matrix_t *mat, const char* name) { - int i,j; - - printf(">>> Matrix %s dump (%d x %d)\n",name,mat->rows,mat->cols); - for (i=0; irows; i++) { - printf(" "); - for (j=0; jcols; j++) - printf(" %.2f",mat->ctn[i*mat->cols + j]); - printf("\n"); - } - printf("<<< end of matrix %s dump\n",name); -} +XBT_LOG_NEW_DEFAULT_CATEGORY(MatMult, "Messages specific to this example"); /* register messages which may be sent and their payload (common to client and server) */ -static void register_messages(void) { +void mmrpc_register_messages(void) +{ gras_datadesc_type_t matrix_type, request_type; - matrix_type=gras_datadesc_by_symbol(s_matrix); - request_type=gras_datadesc_array_fixed("matrix_t[2]",matrix_type,2); - + matrix_type = gras_datadesc_matrix(gras_datadesc_by_name("double"), + NULL); + request_type = + gras_datadesc_array_fixed("s_matrix_t(double)[2]", matrix_type, 2); + gras_msgtype_declare("answer", matrix_type); gras_msgtype_declare("request", request_type); } -/* Function prototypes */ -int server (int argc,char *argv[]); -int client (int argc,char *argv[]); +typedef xbt_matrix_t request_t[2]; +static int server_cb_request_handler(gras_msg_cb_ctx_t ctx, + void *payload_data) +{ -/* ********************************************************************** - * Server code - * **********************************************************************/ + gras_socket_t expeditor = gras_msg_cb_ctx_from(ctx); -static int server_cb_request_handler(gras_socket_t expeditor, void *payload_data) { - /* 1. Get the payload into the data variable */ - matrix_t *data=(matrix_t*)payload_data; - matrix_t result; - int i,j,k; - - /* 2. Make some room to return the result */ - result.rows = data[0].rows; - result.cols = data[1].cols; - result.ctn = xbt_malloc0(sizeof(double) * result.rows * result.cols); - - /* 3. Do the computation */ - for (i=0; i>>>>>>> Connected to server which is on %s:%d <<<<<<<<", - gras_socket_peer_name(toserver),gras_socket_peer_port(toserver)); + XBT_INFO(">>>>>>>> Connected to server which is on %s:%d <<<<<<<<", + gras_socket_peer_name(toserver), gras_socket_peer_port(toserver)); /* 7. Prepare and send the request to the server */ - request[0].rows=request[0].cols=request[1].rows=request[1].cols=MATSIZE; + request[0] = xbt_matrix_double_new_id(MATSIZE, MATSIZE); + request[1] = xbt_matrix_double_new_rand(MATSIZE, MATSIZE); - request[0].ctn=xbt_malloc0(sizeof(double)*MATSIZE*MATSIZE); - request[1].ctn=xbt_malloc0(sizeof(double)*MATSIZE*MATSIZE); + /* + xbt_matrix_dump(request[0],"C:sent0",0,xbt_matrix_dump_display_double); + xbt_matrix_dump(request[1],"C:sent1",0,xbt_matrix_dump_display_double); + */ - for (i=0; i>>>>>>> Request sent to %s:%d <<<<<<<<", - gras_socket_peer_name(toserver),gras_socket_peer_port(toserver)); + XBT_INFO(">>>>>>>> Request sent to %s:%d <<<<<<<<", + gras_socket_peer_name(toserver), gras_socket_peer_port(toserver)); /* 8. Wait for the answer from the server, and deal with issues */ - gras_msg_wait(6000,gras_msgtype_by_name("answer"),&from,&answer); - - /* mat_dump(&answer,"C:answer");*/ - for (i=0; i>>>>>>> Got answer from %s:%d <<<<<<<<", - gras_socket_peer_name(from),gras_socket_peer_port(from)); + XBT_INFO(">>>>>>>> Got answer from %s:%d (values are right) <<<<<<<<", + gras_socket_peer_name(from), gras_socket_peer_port(from)); /* 10. Free the allocated resources, and shut GRAS down */ + xbt_matrix_free(request[1]); + xbt_matrix_free(answer); gras_socket_close(toserver); gras_exit(); - INFO0("Done."); + XBT_INFO("Done."); return 0; -} /* end_of_client */ +} /* end_of_client */