Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ada22e374d5cc9b90f244c72f6a15ef66c5b9edd
[simgrid.git] / teshsuite / msg / process-yield / process-yield.c
1 /* Copyright (c) 2017. The SimGrid Team. All rights reserved.               */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "simgrid/msg.h"
7
8 /* This example does not much: It just spans over-polite processes that yield a large amount
9  * of time before ending.
10  *
11  * This serves as an example for the MSG_process_yield() function, with which a process can request
12  * to be rescheduled after the other processes that are ready at the current timestamp.
13  *
14  * It can also be used to benchmark our context-switching mechanism.
15  */
16
17 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_async_yield, "Messages specific for this msg example");
18
19 /* Main function of the Yielder process */
20 static int yielder(int argc, char* argv[])
21 {
22   xbt_assert(argc == 2, "The sender function expects 1 arguments from the XML deployment file");
23   long number_of_yields = xbt_str_parse_int(argv[1], "Invalid amount of yields: %s"); /* - number of yields */
24
25   for (int i = 0; i < number_of_yields; i++)
26     MSG_process_yield();
27   XBT_INFO("I yielded %ld times. Goodbye now!", number_of_yields);
28   return 0;
29 }
30
31 int main(int argc, char* argv[])
32 {
33   MSG_init(&argc, argv);
34   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
35                        "\tExample: %s msg_platform.xml msg_deployment.xml\n",
36              argv[0], argv[0]);
37
38   MSG_create_environment(argv[1]); /* - Load the platform description */
39
40   MSG_function_register("yielder", yielder);
41   MSG_launch_application(argv[2]); /* - Deploy the sender and receiver processes */
42
43   msg_error_t res = MSG_main(); /* - Run the simulation */
44
45   return res != MSG_OK;
46 }