X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/520f4715694523f1ac80803a19267eaf5ac60f9d..963aa331797f0bc1a8173af4b3970205bcbfbd0c:/examples/gras/mmrpc/mmrpc.c diff --git a/examples/gras/mmrpc/mmrpc.c b/examples/gras/mmrpc/mmrpc.c index fce8447332..de43577630 100644 --- a/examples/gras/mmrpc/mmrpc.c +++ b/examples/gras/mmrpc/mmrpc.c @@ -7,81 +7,48 @@ /* 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 +#define GRAS_DEFINE_TYPE_EXTERN +#include "xbt/matrix.h" +#include "mmrpc.h" 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; - -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); -} - /* 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 - * **********************************************************************/ - -static int server_cb_request_handler(gras_socket_t expeditor, void *payload_data) { + gras_socket_t expeditor=gras_msg_cb_ctx_from(ctx); /* 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 <<<<<<<<", @@ -172,39 +134,41 @@ int client(int argc,char *argv[]) { /* 7. Prepare and send the request to the server */ - request[0].rows=request[0].cols=request[1].rows=request[1].cols=MATSIZE; - - request[0].ctn=xbt_malloc0(sizeof(double)*MATSIZE*MATSIZE); - request[1].ctn=xbt_malloc0(sizeof(double)*MATSIZE*MATSIZE); + request[0] = xbt_matrix_double_new_id(MATSIZE,MATSIZE); + request[1] = xbt_matrix_double_new_rand(MATSIZE,MATSIZE); - for (i=0; i>>>>>>> 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 <<<<<<<<", + INFO2(">>>>>>>> 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.");