예제 #1
0
int main(int argc, char *argv[])
{
  MSG_init(&argc, argv);
  if (argc != 3) {
    printf("Usage: %s platform_file deployment_file\n", argv[0]);
    printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
    exit(1);
  }
  const char *platform_file = argv[1];
  const char *application_file = argv[2];
  MSG_create_environment(platform_file);
  MSG_function_register("receiver", receiver);
  MSG_function_register("sender", sender);

  MSG_launch_application(application_file);
#ifndef DISABLE_THE_MUTEX
  mutex = xbt_mutex_init();
#endif
  msg_error_t res = MSG_main();
#ifndef DISABLE_THE_MUTEX
  xbt_mutex_destroy(mutex); mutex = NULL;
#endif
  XBT_INFO("Simulation time %g", MSG_get_clock());

  if (res == MSG_OK)
    return 0;
  else
    return 1;
}
예제 #2
0
/** Main function */
int main(int argc, char *argv[])
{
    msg_error_t res = MSG_OK;

    /* Argument checking */
    MSG_init(&argc, argv);
    if (argc < 3) {
        XBT_CRITICAL("Usage: %s platform_file deployment_file\n", argv[0]);
        XBT_CRITICAL("example: %s msg_platform.xml msg_deployment_suspend.xml\n",
                     argv[0]);
        exit(1);
    }

    /* Simulation setting */
    MSG_create_environment(argv[1]);

    /* Application deployment */
    MSG_function_register("emigrant", emigrant);
    MSG_function_register("policeman", policeman);
    MSG_launch_application(argv[2]);

    /* Run the simulation */
    mutex = xbt_mutex_init();
    cond = xbt_cond_init();
    res = MSG_main();
    XBT_INFO("Simulation time %g", MSG_get_clock());
    xbt_cond_destroy(cond);
    xbt_mutex_destroy(mutex);

    if (res == MSG_OK)
        return 0;
    else
        return 1;
}                               /* end_of_main */
예제 #3
0
void smpi_global_init(void)
{
  int i;
  MPI_Group group;
  char name[MAILBOX_NAME_MAXLEN];
  int smpirun=0;

  if (!MC_is_active()) {
    global_timer = xbt_os_timer_new();
    xbt_os_walltimer_start(global_timer);
  }
  if (process_count == 0){
    process_count = SIMIX_process_count();
    smpirun=1;
  }
  smpi_universe_size = process_count;
  process_data = xbt_new0(smpi_process_data_t, process_count);
  for (i = 0; i < process_count; i++) {
    process_data[i]                       = xbt_new(s_smpi_process_data_t, 1);
    //process_data[i]->index              = i;
    process_data[i]->argc                 = NULL;
    process_data[i]->argv                 = NULL;
    process_data[i]->mailbox              = simcall_rdv_create(get_mailbox_name(name, i));
    process_data[i]->mailbox_small        =
        simcall_rdv_create(get_mailbox_name_small(name, i));
    process_data[i]->mailboxes_mutex      = xbt_mutex_init();
    process_data[i]->timer                = xbt_os_timer_new();
    if (MC_is_active())
      MC_ignore_heap(process_data[i]->timer, xbt_os_timer_size());
    process_data[i]->comm_self            = MPI_COMM_NULL;
    process_data[i]->comm_intra           = MPI_COMM_NULL;
    process_data[i]->comm_world           = NULL;
    process_data[i]->state                = SMPI_UNINITIALIZED;
    process_data[i]->sampling             = 0;
    process_data[i]->finalization_barrier = NULL;
  }
  //if the process was launched through smpirun script
  //we generate a global mpi_comm_world
  //if not, we let MPI_COMM_NULL, and the comm world
  //will be private to each mpi instance
  if(smpirun){
    group = smpi_group_new(process_count);
    MPI_COMM_WORLD = smpi_comm_new(group, NULL);
    MPI_Attr_put(MPI_COMM_WORLD, MPI_UNIVERSE_SIZE, (void *)(MPI_Aint)process_count);
    xbt_bar_t bar=xbt_barrier_init(process_count);

    for (i = 0; i < process_count; i++) {
      smpi_group_set_mapping(group, i, i);
      process_data[i]->finalization_barrier = bar;
    }
  }
}
예제 #4
0
/** @brief Create a new message exchange queue.
 *
 * @param capacity the capacity of the queue. If non-nul, any attempt to push an item which would let the size of the queue over this number will be blocking until someone else pop some data
 * @param elm_size size of each element stored in it (see #xbt_dynar_new)
 */
xbt_queue_t xbt_queue_new(int capacity, unsigned long elm_size)
{
  xbt_queue_t res = xbt_new0(s_xbt_queue_t, 1);
  if (capacity<0)
    capacity=0;

  res->capacity = capacity;
  res->data = xbt_dynar_new(elm_size, NULL);
  res->mutex = xbt_mutex_init();
  res->not_full = xbt_cond_init();
  res->not_empty = xbt_cond_init();
  return res;
}
예제 #5
0
xbt_thread_t xbt_thread_create(const char *name, void_f_pvoid_t code,
                               void *param, int joinable)
{
  xbt_thread_t res = xbt_new0(s_xbt_thread_t, 1);
  res->name = xbt_strdup(name);
  res->userparam = param;
  res->code = code;
  res->father_data = SIMIX_process_self_get_data(SIMIX_process_self());
  /*   char*name = bprintf("%s#%p",SIMIX_process_self_get_name(), param); */
  simcall_process_create(&res->s_process, name,
                           xbt_thread_create_wrapper, res,
                           SIMIX_host_self_get_name(), -1.0, 0, NULL,
                           /*props */ NULL,0);
  res->joinable = joinable;
  res->done = 0;
  res->cond = xbt_cond_init();
  res->mutex = xbt_mutex_init();
  //   free(name);
  return res;
}
예제 #6
0
int main(int argc, char *argv[])
{
  MSG_init(&argc, argv);
  xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
       "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);

  MSG_create_environment(argv[1]);
  MSG_function_register("receiver", receiver);
  MSG_function_register("sender", sender);

  MSG_launch_application(argv[2]);
#ifndef DISABLE_THE_MUTEX
  mutex = xbt_mutex_init();
#endif
  msg_error_t res = MSG_main();
#ifndef DISABLE_THE_MUTEX
  xbt_mutex_destroy(mutex); mutex = NULL;
#endif
  XBT_INFO("Simulation time %g", MSG_get_clock());

  return res != MSG_OK;
}
예제 #7
0
JNIEXPORT void JNICALL Java_org_simgrid_msg_Mutex_init(JNIEnv * env, jobject obj) {
  xbt_mutex_t mutex = xbt_mutex_init();

  env->SetLongField(obj, jsyncro_field_Mutex_bind, (jlong) (uintptr_t) (mutex));
}