-void smpi_mpi_init() {
- int i;
- int size, rank;
- smx_host_t *hosts;
- smx_host_t host;
- double duration;
- m_task_t mtask;
-
- // will eventually need mutex
- smpi_running_hosts++;
-
- // initialize some local variables
- size = SIMIX_host_get_number();
- host = SIMIX_host_self();
- hosts = SIMIX_host_get_table();
- for(i = 0; i < size && host != hosts[i]; i++);
- rank = i;
-
- // node 0 sets the globals
- if (0 == rank) {
-
- // global communicator
- smpi_mpi_comm_world.id = 0;
- smpi_mpi_comm_world.size = size;
- smpi_mpi_comm_world.barrier = 0;
- smpi_mpi_comm_world.hosts = hosts;
- smpi_mpi_comm_world.processes = xbt_malloc(sizeof(m_process_t) * size);
- smpi_mpi_comm_world.processes[0] = SIMIX_process_self();
-
- // mpi datatypes
- smpi_mpi_byte.size = (size_t)1;
- smpi_mpi_int.size = sizeof(int);
- smpi_mpi_double.size = sizeof(double);
-
- // mpi operations
- smpi_mpi_land.func = &smpi_mpi_land_func;
- smpi_mpi_sum.func = &smpi_mpi_sum_func;
-
- // smpi globals
- smpi_pending_send_requests = xbt_malloc(sizeof(smpi_mpi_request_t*) * size);
- smpi_last_pending_send_requests = xbt_malloc(sizeof(smpi_mpi_request_t*) * size);
- smpi_pending_recv_requests = xbt_malloc(sizeof(smpi_mpi_request_t*) * size);
- smpi_last_pending_recv_requests = xbt_malloc(sizeof(smpi_mpi_request_t*) * size);
- smpi_received = xbt_malloc(sizeof(smpi_received_t*) * size);
- smpi_last_received = xbt_malloc(sizeof(smpi_received_t*) * size);
- smpi_sender_processes = xbt_malloc(sizeof(m_process_t) * size);
- smpi_receiver_processes = xbt_malloc(sizeof(m_process_t) * size);
- for(i = 0; i < size; i++) {
- smpi_pending_send_requests[i] = NULL;
- smpi_last_pending_send_requests[i] = NULL;
- smpi_pending_recv_requests[i] = NULL;
- smpi_last_pending_recv_requests[i] = NULL;
- smpi_received[i] = NULL;
- smpi_last_received[i] = NULL;
- }
- smpi_timer = xbt_os_timer_new();
- smpi_reference = DEFAULT_POWER;
- smpi_benchmarking = 0;
-
- // tell send/recv nodes to begin
- for(i = 0; i < size; i++) {
- mtask = MSG_task_create("READY", 0, 0, NULL);
- MSG_task_put(mtask, hosts[i], SEND_SYNC_PORT);
- mtask = (m_task_t)0;
- MSG_task_get_from_host(&mtask, SEND_SYNC_PORT, hosts[i]);
- MSG_task_destroy(mtask);
- mtask = MSG_task_create("READY", 0, 0, NULL);
- MSG_task_put(mtask, hosts[i], RECV_SYNC_PORT);
- mtask = (m_task_t)0;
- MSG_task_get_from_host(&mtask, RECV_SYNC_PORT, hosts[i]);
- MSG_task_destroy(mtask);
- }
-
- // now everyone else
- for(i = 1; i < size; i++) {
- mtask = MSG_task_create("READY", 0, 0, NULL);
- MSG_task_put(mtask, hosts[i], MPI_PORT);
- }
-
- } else {
- // everyone needs to wait for node 0 to finish
- mtask = (m_task_t)0;
- MSG_task_get(&mtask, MPI_PORT);
- MSG_task_destroy(mtask);
- smpi_mpi_comm_world.processes[rank] = SIMIX_process_self();
- }
-
- // now that mpi_comm_world_processes is set, it's safe to set a barrier
- smpi_barrier(&smpi_mpi_comm_world);
-}