- smx_process_t process;
- smx_host_t host;
- smx_host_t *hosts;
- int size;
-
- SIMIX_mutex_lock(smpi_global->running_hosts_count_mutex);
- smpi_global->running_hosts_count++;
- SIMIX_mutex_unlock(smpi_global->running_hosts_count_mutex);
-
- // initialize some local variables
- process = SIMIX_process_self();
- host = SIMIX_host_self();
- hosts = SIMIX_host_get_table();
- size = SIMIX_host_get_number();
-
- // node 0 sets the globals
- if (host == hosts[0]) {
-
- smpi_mpi_global = xbt_new(s_SMPI_MPI_Global_t, 1);
-
- // global communicator
- smpi_mpi_global->mpi_comm_world = xbt_new(s_smpi_mpi_communicator_t, 1);
- smpi_mpi_global->mpi_comm_world->size = size;
- smpi_mpi_global->mpi_comm_world->hosts = hosts;
- smpi_mpi_global->mpi_comm_world->processes = xbt_new(smx_process_t, size);
- smpi_mpi_global->mpi_comm_world->processes[0] = process;
- smpi_mpi_global->mpi_comm_world->barrier_count = 0;
- smpi_mpi_global->mpi_comm_world->barrier_mutex = SIMIX_mutex_init();
- smpi_mpi_global->mpi_comm_world->barrier_cond = SIMIX_cond_init();
-
- // mpi datatypes
- smpi_mpi_global->mpi_byte = xbt_new(s_smpi_mpi_datatype_t, 1);
- smpi_mpi_global->mpi_byte->size = (size_t)1;
- smpi_mpi_global->mpi_int = xbt_new(s_smpi_mpi_datatype_t, 1);
- smpi_mpi_global->mpi_int->size = sizeof(int);
- smpi_mpi_global->mpi_double = xbt_new(s_smpi_mpi_datatype_t, 1);
- smpi_mpi_global->mpi_double->size = sizeof(double);
-
- // mpi operations
- smpi_mpi_global->mpi_land = xbt_new(s_smpi_mpi_op_t, 1);
- smpi_mpi_global->mpi_land->func = smpi_mpi_land_func;
- smpi_mpi_global->mpi_sum = xbt_new(s_smpi_mpi_op_t, 1);
- smpi_mpi_global->mpi_sum->func = smpi_mpi_sum_func;
-
- // signal all nodes to perform initialization
- SIMIX_mutex_lock(smpi_global->start_stop_mutex);
- smpi_global->root_ready = 1;
- SIMIX_cond_broadcast(smpi_global->start_stop_cond);
- SIMIX_mutex_unlock(smpi_global->start_stop_mutex);
-
- } else {
-
- // make sure root is done before own initialization
- SIMIX_mutex_lock(smpi_global->start_stop_mutex);
- if (!smpi_global->root_ready) {
- SIMIX_cond_wait(smpi_global->start_stop_cond, smpi_global->start_stop_mutex);
- }
- SIMIX_mutex_unlock(smpi_global->start_stop_mutex);
-
- smpi_mpi_global->mpi_comm_world->processes[smpi_mpi_comm_rank_self(smpi_mpi_global->mpi_comm_world)] = process;
- }
-
- // wait for all nodes to signal initializatin complete
- SIMIX_mutex_lock(smpi_global->start_stop_mutex);
- smpi_global->ready_process_count++;
- if (smpi_global->ready_process_count < 3 * size) {
- SIMIX_cond_wait(smpi_global->start_stop_cond, smpi_global->start_stop_mutex);
- } else {
- SIMIX_cond_broadcast(smpi_global->start_stop_cond);
- }
- SIMIX_mutex_unlock(smpi_global->start_stop_mutex);
-
- return;
+ smpi_process_data_t pdata;
+
+ // initialize some local variables
+
+ pdata = xbt_new(s_smpi_process_data_t, 1);
+ SIMIX_process_set_data(SIMIX_process_self(),pdata);
+
+ /* get rank from command line, and remove it from argv */
+ pdata->index = atoi( (*argv)[1] );
+ DEBUG1("I'm rank %d",pdata->index);
+ if (*argc>2) {
+ memmove((*argv)[1],(*argv)[2], sizeof(char*)* (*argc-2));
+ (*argv)[ (*argc)-1] = NULL;
+ }
+ (*argc)--;
+
+ pdata->mutex = SIMIX_mutex_init();
+ pdata->cond = SIMIX_cond_init();
+ pdata->finalize = 0;
+
+ pdata->pending_recv_request_queue = xbt_fifo_new();
+ pdata->pending_send_request_queue = xbt_fifo_new();
+ pdata->received_message_queue = xbt_fifo_new();
+
+ pdata->main = SIMIX_process_self();
+ pdata->sender = SIMIX_process_create("smpi_sender",
+ smpi_sender, pdata,
+ SIMIX_host_get_name(SIMIX_host_self()), 0, NULL,
+ /*props */ NULL);
+ pdata->receiver = SIMIX_process_create("smpi_receiver",
+ smpi_receiver, pdata,
+ SIMIX_host_get_name(SIMIX_host_self()), 0, NULL,
+ /*props */ NULL);
+
+ smpi_global->main_processes[pdata->index] = SIMIX_process_self();
+ return;