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
13 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(MatMult);
15 int client(int argc,char *argv[]) {
17 gras_socket_t toserver=NULL; /* peer */
20 matrix_t request[2], answer;
24 const char *host = "127.0.0.1";
27 /* 1. Init the GRAS's infrastructure */
28 gras_init(&argc, argv);
30 /* 2. Get the server's address. The command line override defaults when specified */
36 INFO2("Launch client (server on %s:%d)",host,port);
38 /* 3. Wait for the server startup */
41 /* 4. Create a socket to speak to the server */
43 toserver=gras_socket_client(host,port);
45 RETHROW0("Unable to connect to the server: %s");
47 INFO2("Connected to %s:%d.",host,port);
50 /* 5. Register the messages (before use) */
51 mmrpc_register_messages();
53 /* 6. Keep the user informed of what's going on */
54 INFO2(">>>>>>>> Connected to server which is on %s:%d <<<<<<<<",
55 gras_socket_peer_name(toserver),gras_socket_peer_port(toserver));
57 /* 7. Prepare and send the request to the server */
59 request[0].rows=request[0].cols=request[1].rows=request[1].cols=MATSIZE;
61 request[0].ctn=xbt_malloc0(sizeof(double)*MATSIZE*MATSIZE);
62 request[1].ctn=xbt_malloc0(sizeof(double)*MATSIZE*MATSIZE);
64 for (i=0; i<MATSIZE; i++) {
65 request[0].ctn[i*MATSIZE+i] = 1;
66 for (j=0; j<MATSIZE; j++)
67 request[1].ctn[i*MATSIZE+j] = i*MATSIZE+j;
69 /* mat_dump(&request[0],"C:sent0");*/
70 /* mat_dump(&request[1],"C:sent1");*/
72 gras_msg_send(toserver, gras_msgtype_by_name("request"), &request);
77 INFO2(">>>>>>>> Request sent to %s:%d <<<<<<<<",
78 gras_socket_peer_name(toserver),gras_socket_peer_port(toserver));
80 /* 8. Wait for the answer from the server, and deal with issues */
81 gras_msg_wait(6000,gras_msgtype_by_name("answer"),&from,&answer);
83 /* mat_dump(&answer,"C:answer");*/
84 for (i=0; i<MATSIZE*MATSIZE; i++)
85 xbt_assert(answer.ctn[i]==i);
87 /* 9. Keep the user informed of what's going on, again */
88 INFO2(">>>>>>>> Got answer from %s:%d <<<<<<<<",
89 gras_socket_peer_name(from),gras_socket_peer_port(from));
91 /* 10. Free the allocated resources, and shut GRAS down */
93 gras_socket_close(toserver);