this is the code( not a complete code)

int master(int argc, char *argv[])
{
  int slaves_count = 0;
  m_host_t *slaves = NULL;
  m_task_t *todo = NULL;
  int number_of_tasks = 0;
  double task_comp_size = 0;
  double task_comm_size = 0;


  int i;

  xbt_assert1(sscanf(argv[1],"%d", &number_of_tasks),
     "Invalid argument %s\n",argv[1]);
  xbt_assert1(sscanf(argv[2],"%lg", &task_comp_size),
     "Invalid argument %s\n",argv[2]);
  xbt_assert1(sscanf(argv[3],"%lg", &task_comm_size),
     "Invalid argument %s\n",argv[3]);

  {                  /*  Task creation */
    char sprintf_buffer[64];

    todo = calloc(number_of_tasks, sizeof(m_task_t));

    for (i = 0; i < number_of_tasks; i++) {
      sprintf(sprintf_buffer, "Task_%d", i);
      todo[i] = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL);
    }
  }

  {                  /* Process organisation */
    slaves_count = argc - 4;
    slaves = calloc(slaves_count, sizeof(m_host_t));
    
    for (i = 4; i < argc; i++) {
      slaves[i-4] = MSG_get_host_by_name(argv[i]);
      if(slaves[i-4]==NULL) {
    INFO1("Unknown host %s. Stopping Now! ", argv[i]);
    abort();
      }
    }
  }

  INFO1("Got %d slave(s) :", slaves_count);
  for (i = 0; i < slaves_count; i++)
    INFO1("\t %s", slaves[i]->name);

  INFO1("Got %d task to process :", number_of_tasks);

  for (i = 0; i < number_of_tasks; i++)
    INFO1("\t\"%s\"", todo[i]->name);

  for (i = 0; i < number_of_tasks; i++) {
    INFO2("Sending \"%s\" to \"%s\"",
                  todo[i]->name,
                  slaves[i % slaves_count]->name);
    if(MSG_host_self()==slaves[i % slaves_count]) {
      INFO0("Hey ! It's me ! :)");
    }
    MSG_task_put(todo[i], slaves[i % slaves_count],
                 PORT_22);
    INFO0("Send completed");
  }
  
  INFO0("All tasks have been dispatched. Let's tell everybody the computation is over.");
  for (i = 0; i < slaves_count; i++) 
    MSG_task_put(MSG_task_create("finalize", 0, 0, FINALIZE),
         slaves[i], PORT_22);
  
  INFO0("Goodbye now!");
  free(slaves);
  free(todo);
  return 0;
} /* end_of_master */

int slave(int argc, char *argv[])
{
  while(1) {
    m_task_t task = NULL;
    int a;
    a = MSG_task_get(&(task), PORT_22);
    if (a == MSG_OK) {
      INFO1("Received \"%s\" ", MSG_task_get_name(task));
      if(MSG_task_get_data(task)==FINALIZE) {
    MSG_task_destroy(task);
    break;
      }
      INFO1("Processing \"%s\" ", MSG_task_get_name(task));
      MSG_task_execute(task);
      INFO1("\"%s\" done ", MSG_task_get_name(task));
      MSG_task_destroy(task);
    } else {
      INFO0("Hey ?! What's up ? ");
      xbt_assert0(0,"Unexpected behavior");
    }
  }
  INFO0("I'm done. See you!");
  return 0;
} /* end_of_slave */

how do i change this code so that it will produce output that list down all the task handled by particular slave
something like this

master = (master name)

slave
(name of slave1)
(list of tasks handled by slave1)

(name of slave2)
(list of tasks handled by slave2)

...

i've been trying all day but still dont get the output
i need help:?:

Post the declarations of m_task_t and m_host_t and this time use BB code tags.
Is m_task_t some kinda pointer? Or the following code is wrong..
m_task_t *todo = NULL;
m_task_t task = NULL;

Don't write normal code within asserts (usually they are removed by pre-processor in release mode).

Finally a few more comments in code would help. Also who calls these functions in which order? And which function is supposed to print the stuff you wanna print?

int master(int argc, char *argv[])
{
    int slaves_count = 0;
    m_host_t *slaves = NULL;
    m_task_t *todo = NULL;
    int number_of_tasks = 0;
    double task_comp_size = 0;
    double task_comm_size = 0;


    int i;

    xbt_assert1(sscanf(argv[1],"%d", &number_of_tasks),
    "Invalid argument %s\n",argv[1]);
    xbt_assert1(sscanf(argv[2],"%lg", &task_comp_size),
    "Invalid argument %s\n",argv[2]);
    xbt_assert1(sscanf(argv[3],"%lg", &task_comm_size),
    "Invalid argument %s\n",argv[3]);

    { /* Task creation */
        char sprintf_buffer[64];

        todo = calloc(number_of_tasks, sizeof(m_task_t));

        for (i = 0; i < number_of_tasks; i++) {
            sprintf(sprintf_buffer, "Task_%d", i);
            todo[i] = MSG_task_create(sprintf_buffer,
                         task_comp_size, task_comm_size, NULL);
        }
    }

    { /* Process organisation */
        slaves_count = argc - 4;
        slaves = calloc(slaves_count, sizeof(m_host_t));

        for (i = 4; i < argc; i++) {
            slaves[i-4] = MSG_get_host_by_name(argv[i]);
            if(slaves[i-4]==NULL) {
                INFO1("Unknown host %s. Stopping Now! ", argv[i]);
                abort();
            }
        }
    }

    INFO1("Got %d slave(s) :", slaves_count);
    for (i = 0; i < slaves_count; i++)
        INFO1("\t %s", slaves[i]->name);

    INFO1("Got %d task to process :", number_of_tasks);

    for (i = 0; i < number_of_tasks; i++)
        INFO1("\t\"%s\"", todo[i]->name);

    for (i = 0; i < number_of_tasks; i++) {
        INFO2("Sending \"%s\" to \"%s\"",
        todo[i]->name,
        slaves[i % slaves_count]->name);
        if(MSG_host_self()==slaves[i % slaves_count]) {
            INFO0("Hey ! It's me ! ");
        }
        MSG_task_put(todo[i], slaves[i % slaves_count],
        PORT_22);
        INFO0("Send completed");
    }

    INFO0("All tasks have been dispatched. \
            Let's tell everybody the computation is over.");
    for (i = 0; i < slaves_count; i++)
    MSG_task_put(MSG_task_create("finalize", 0, 0, FINALIZE),
    slaves[i], PORT_22);

    INFO0("Goodbye now!");
    free(slaves);
    free(todo);
    return 0;
} /* end_of_master */

int slave(int argc, char *argv[])
{
    while(1) {
        m_task_t task = NULL;
        int a;
        a = MSG_task_get(&(task), PORT_22);
        if (a == MSG_OK) {
            INFO1("Received \"%s\" ", MSG_task_get_name(task));
            if(MSG_task_get_data(task)==FINALIZE) {
                MSG_task_destroy(task);
                break;
            }
            INFO1("Processing \"%s\" ", MSG_task_get_name(task));
            MSG_task_execute(task);
            INFO1("\"%s\" done ", MSG_task_get_name(task));
            MSG_task_destroy(task);
        }
        else {
            INFO0("Hey ?! What's up ? ");
            xbt_assert0(0,"Unexpected behavior");
        }
    }
    INFO0("I'm done. See you!");
    return 0;
} /* end_of_slave */
This article has been dead for over six months. Start a new discussion instead.