3 /* GridRPC - Fake Grid RPC thingy doing matrix multiplications (as expected)*/
5 /* Copyright (c) 2005 Martin Quinson. All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify it
8 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #define GRAS_DEFINE_TYPE_EXTERN
11 #include "xbt/matrix.h"
14 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(MatMult);
16 int client(int argc,char *argv[]) {
18 gras_socket_t toserver=NULL; /* peer */
21 xbt_matrix_t request[2], answer;
25 const char *host = "127.0.0.1";
28 /* 1. Init the GRAS's infrastructure */
29 gras_init(&argc, argv);
31 /* 2. Get the server's address. The command line override defaults when specified */
37 INFO2("Launch client (server on %s:%d)",host,port);
39 /* 3. Wait for the server startup */
42 /* 4. Create a socket to speak to the server */
44 toserver=gras_socket_client(host,port);
46 RETHROW0("Unable to connect to the server: %s");
48 INFO2("Connected to %s:%d.",host,port);
51 /* 5. Register the messages (before use) */
52 mmrpc_register_messages();
54 /* 6. Keep the user informed of what's going on */
55 INFO2(">>>>>>>> Connected to server which is on %s:%d <<<<<<<<",
56 gras_socket_peer_name(toserver),gras_socket_peer_port(toserver));
58 /* 7. Prepare and send the request to the server */
60 request[0] = xbt_matrix_double_new_id(MATSIZE,MATSIZE);
61 request[1] = xbt_matrix_double_new_rand(MATSIZE,MATSIZE);
64 xbt_matrix_dump(request[0],"C:sent0",0,xbt_matrix_dump_display_double);
65 xbt_matrix_dump(request[1],"C:sent1",0,xbt_matrix_dump_display_double);
68 gras_msg_send(toserver, gras_msgtype_by_name("request"), &request);
70 xbt_matrix_free(request[0]);
72 INFO2(">>>>>>>> Request sent to %s:%d <<<<<<<<",
73 gras_socket_peer_name(toserver),gras_socket_peer_port(toserver));
75 /* 8. Wait for the answer from the server, and deal with issues */
76 gras_msg_wait(6000,gras_msgtype_by_name("answer"),&from,&answer);
79 xbt_matrix_dump(answer,"C:answer",0,xbt_matrix_dump_display_double);
81 for (i=0; i<MATSIZE; i++)
82 for (j=0; i<MATSIZE; i++)
83 xbt_assert4(xbt_matrix_get_as(answer,i,j,double)==xbt_matrix_get_as(request[1],i,j,double),
84 "Answer does not match expectations. Found %f at cell %d,%d instead of %f",
85 xbt_matrix_get_as(answer,i,j,double),i,j,
86 xbt_matrix_get_as(request[1],i,j,double));
88 /* 9. Keep the user informed of what's going on, again */
89 INFO2(">>>>>>>> Got answer from %s:%d (values are right) <<<<<<<<",
90 gras_socket_peer_name(from),gras_socket_peer_port(from));
92 /* 10. Free the allocated resources, and shut GRAS down */
93 xbt_matrix_free(request[1]);
94 xbt_matrix_free(answer);
95 gras_socket_close(toserver);