12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- /*
- * mycoagent.c
- *
- * This is an example agent that showcases the use of mycorrhiza.
- */
- #include <time.h>
- #include "../../src/myco-agent.c"
- int main (int argc, char *argv []) {
- int message_count = atoi (argv [1]);
- unsigned long throughput;
- double megabits;
- if (argc != 2) {
- printf ("usage: send_recv <message-count>\n");
- return 1;
- }
-
- char *agent_name = "DOMAIN1_MYAGENT";
- int agent_message_queue_id = myco_agent_register(agent_name);
- struct resource myresource;
- myresource = myco_agent_read_remote_resource(agent_message_queue_id, "RESOURCE");
- if (myresource.size != -1) {
- printf("The first integer of RESOURCE is: %d\n", *((int*)myresource.pointer));
- }
- clock_t start, end;
- long double elapsed;
- start = clock();
- for (int i = 0; i != message_count; i++) {
- myco_agent_write_remote_resource(agent_message_queue_id, "RESOURCE", myresource.pointer, myresource.size, 1);
- }
- end = clock();
- elapsed = end - start;
- if (elapsed == 0)
- elapsed = 1;
-
- throughput = (unsigned long)
- ((double) message_count / (double) elapsed * 1000000);
- megabits = ((double) throughput * myresource.size * 8) / 1000000;
-
- printf("message size: %d [B]\n", myresource.size);
- printf("message count: %d\n", message_count);
- printf("mean throughput: %d [msg/s]\n", (int)throughput);
- printf("mean throughput: %.3f [Mb/s]\n", (double)megabits);
- myco_agent_unregister_resource(agent_message_queue_id, "RESOURCE");
- myco_agent_unregister(agent_name, agent_message_queue_id);
- return EXIT_SUCCESS;
- }
|