Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
removing references to mpi_comm_world from internal code
authormarkls <markls@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sat, 8 Sep 2007 01:50:00 +0000 (01:50 +0000)
committermarkls <markls@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sat, 8 Sep 2007 01:50:00 +0000 (01:50 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@4141 48e7efb5-ca39-0410-a469-dd3cf9ba447f

include/smpi/smpi.h
src/smpi/private.h
src/smpi/smpi_base.c
src/smpi/smpi_bench.c
src/smpi/smpi_global.c
src/smpi/smpi_mpi.c
src/smpi/smpi_receiver.c
src/smpi/smpi_sender.c

index f6f07a6..0e390c8 100644 (file)
@@ -38,7 +38,6 @@ typedef struct smpi_mpi_op_t *smpi_mpi_op_t;
 typedef smpi_mpi_op_t MPI_Op;
 
 // MPI_Status
 typedef smpi_mpi_op_t MPI_Op;
 
 // MPI_Status
-// FIXME: status is kind of an odd duck, is this required by the standard?
 struct smpi_mpi_status_t {
   int MPI_SOURCE;
   int MPI_TAG;
 struct smpi_mpi_status_t {
   int MPI_SOURCE;
   int MPI_TAG;
@@ -64,6 +63,7 @@ typedef struct smpi_mpi_global_t *smpi_mpi_global_t;
 extern smpi_mpi_global_t smpi_mpi_global;
 
 #define MPI_COMM_WORLD    (smpi_mpi_global->mpi_comm_world)
 extern smpi_mpi_global_t smpi_mpi_global;
 
 #define MPI_COMM_WORLD    (smpi_mpi_global->mpi_comm_world)
+#define MPI_COMM_NULL     NULL
 
 #define MPI_STATUS_IGNORE NULL
 
 
 #define MPI_STATUS_IGNORE NULL
 
index da7560a..804ea9e 100644 (file)
 // smpi mpi communicator
 typedef struct smpi_mpi_communicator_t {
        int            size;
 // smpi mpi communicator
 typedef struct smpi_mpi_communicator_t {
        int            size;
-       smx_host_t    *hosts;
-       smx_process_t *processes;
        int            barrier_count;
        smx_mutex_t    barrier_mutex;
        smx_cond_t     barrier_cond;
        int            barrier_count;
        smx_mutex_t    barrier_mutex;
        smx_cond_t     barrier_cond;
+
+       int           *rank_to_index_map;
+       int           *index_to_rank_map;
+
 } s_smpi_mpi_communicator_t;
 
 // smpi mpi datatype
 } s_smpi_mpi_communicator_t;
 
 // smpi mpi datatype
@@ -35,8 +37,8 @@ typedef struct smpi_mpi_request_t {
        int tag;
 
        void *buf;
        int tag;
 
        void *buf;
-       smpi_mpi_datatype_t datatype;
        int count;
        int count;
+       smpi_mpi_datatype_t datatype;
 
        short int completed :1;
 
 
        short int completed :1;
 
@@ -45,6 +47,8 @@ typedef struct smpi_mpi_request_t {
 } s_smpi_mpi_request_t;
 
 // smpi mpi op
 } s_smpi_mpi_request_t;
 
 // smpi mpi op
+// FIXME: type should be (void *a, void *b, int *length, MPI_Datatype *datatype)
+//, oper is b[i] = a[i] op b[i]
 typedef struct smpi_mpi_op_t {
   void (*func)(void *x, void *y, void *z);
 } s_smpi_mpi_op_t;
 typedef struct smpi_mpi_op_t {
   void (*func)(void *x, void *y, void *z);
 } s_smpi_mpi_op_t;
@@ -53,8 +57,8 @@ typedef struct smpi_mpi_op_t {
 typedef struct smpi_received_message_t {
        smpi_mpi_communicator_t comm;
        int src;
 typedef struct smpi_received_message_t {
        smpi_mpi_communicator_t comm;
        int src;
-       int dst;
        int tag;
        int tag;
+
        void *buf;
 } s_smpi_received_message_t;
 typedef struct smpi_received_message_t *smpi_received_message_t;
        void *buf;
 } s_smpi_received_message_t;
 typedef struct smpi_received_message_t *smpi_received_message_t;
@@ -70,6 +74,8 @@ typedef struct smpi_global_t {
        smx_mutex_t       start_stop_mutex;
        smx_cond_t        start_stop_cond;
 
        smx_mutex_t       start_stop_mutex;
        smx_cond_t        start_stop_cond;
 
+       smx_host_t       *hosts;
+       int               host_count;
        xbt_mallocator_t  request_mallocator;
        xbt_mallocator_t  message_mallocator;
 
        xbt_mallocator_t  request_mallocator;
        xbt_mallocator_t  message_mallocator;
 
@@ -98,10 +104,8 @@ extern smpi_global_t smpi_global;
 // function prototypes
 void smpi_mpi_init(void);
 void smpi_mpi_finalize(void);
 // function prototypes
 void smpi_mpi_init(void);
 void smpi_mpi_finalize(void);
-int smpi_mpi_comm_size(smpi_mpi_communicator_t comm);
-int smpi_mpi_comm_rank(smpi_mpi_communicator_t comm, smx_host_t host);
-int smpi_mpi_comm_rank_self(smpi_mpi_communicator_t comm);
-int smpi_mpi_comm_world_rank_self(void);
+int smpi_mpi_comm_size(smpi_mpi_communicator_t comm, int *size);
+int smpi_mpi_comm_rank(smpi_mpi_communicator_t comm, int *rank);
 int smpi_mpi_barrier(smpi_mpi_communicator_t comm);
 int smpi_mpi_isend(smpi_mpi_request_t request);
 int smpi_mpi_irecv(smpi_mpi_request_t request);
 int smpi_mpi_barrier(smpi_mpi_communicator_t comm);
 int smpi_mpi_isend(smpi_mpi_request_t request);
 int smpi_mpi_irecv(smpi_mpi_request_t request);
@@ -112,6 +116,7 @@ void smpi_bench_end(void);
 
 void smpi_global_init(void);
 void smpi_global_destroy(void);
 
 void smpi_global_init(void);
 void smpi_global_destroy(void);
+int smpi_host_index(void);
 int smpi_run_simulation(int argc, char **argv);
 int smpi_create_request(void *buf, int count, smpi_mpi_datatype_t datatype,
        int src, int dst, int tag, smpi_mpi_communicator_t comm, smpi_mpi_request_t *request);
 int smpi_run_simulation(int argc, char **argv);
 int smpi_create_request(void *buf, int count, smpi_mpi_datatype_t datatype,
        int src, int dst, int tag, smpi_mpi_communicator_t comm, smpi_mpi_request_t *request);
index 8d64b45..bb266ea 100644 (file)
@@ -16,71 +16,86 @@ void smpi_mpi_sum_func(void *x, void *y, void *z)
        *(int *)z = *(int *)x + *(int *)y;
 }
 
        *(int *)z = *(int *)x + *(int *)y;
 }
 
-int inline smpi_mpi_comm_size(smpi_mpi_communicator_t comm)
+int inline smpi_mpi_comm_size(smpi_mpi_communicator_t comm, int *size)
 {
 {
-       return comm->size;
+       int retval = MPI_SUCCESS;
+       if (NULL == size) {
+               retval = MPI_ERR_ARG;
+       } else {
+               *size = comm->size;
+       }
+       return retval;
 }
 
 // FIXME: smarter algorithm?
 }
 
 // FIXME: smarter algorithm?
-int smpi_mpi_comm_rank(smpi_mpi_communicator_t comm, smx_host_t host)
+int smpi_mpi_comm_rank(smpi_mpi_communicator_t comm, int *rank)
 {
        int i;
 {
        int i;
+       int retval = MPI_SUCCESS;
 
 
-       for(i = comm->size - 1; i > 0 && host != comm->hosts[i]; i--);
+       if (NULL == rank) {
+               retval = MPI_ERR_ARG;
+       } else {
+               smx_host_t host = SIMIX_host_self();
 
 
-       return i;
-}
+               for (i = 0; i < comm->size && host != smpi_global->hosts[comm->rank_to_index_map[i]]; i++);
 
 
-int inline smpi_mpi_comm_rank_self(smpi_mpi_communicator_t comm)
-{
-       return smpi_mpi_comm_rank(comm, SIMIX_host_self());
+               *rank = i;
+       }
+
+       return retval;
 }
 
 void smpi_mpi_init()
 {
 }
 
 void smpi_mpi_init()
 {
-       smx_process_t process;
        smx_host_t host;
        smx_host_t *hosts;
        smx_host_t host;
        smx_host_t *hosts;
-       int size;
+       int host_count;
+       int i;
 
        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
 
        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();
+       host       = SIMIX_host_self();
+       hosts      = SIMIX_host_get_table();
+       host_count = SIMIX_host_get_number();
 
        // node 0 sets the globals
        if (host == hosts[0]) {
 
 
        // node 0 sets the globals
        if (host == hosts[0]) {
 
-               smpi_mpi_global                                = xbt_new(s_smpi_mpi_global_t, 1);
+               smpi_global->hosts                              = hosts;
+               smpi_global->host_count                         = host_count;
+
+               smpi_mpi_global                                 = xbt_new(s_smpi_mpi_global_t, 1);
 
                // global communicator
 
                // 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();
+               smpi_mpi_global->mpi_comm_world                 = xbt_new(s_smpi_mpi_communicator_t, 1);
+               smpi_mpi_global->mpi_comm_world->size           = host_count;
+               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();
+               smpi_mpi_global->mpi_comm_world->rank_to_index_map = xbt_new(int, host_count);
+               smpi_mpi_global->mpi_comm_world->index_to_rank_map = xbt_new(int, host_count);
+               for (i = 0; i < host_count; i++) {
+                       smpi_mpi_global->mpi_comm_world->rank_to_index_map[i] = i;
+                       smpi_mpi_global->mpi_comm_world->index_to_rank_map[i] = i;
+               }
 
                // mpi datatypes
 
                // 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);
+               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
 
                // 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;
+               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);
 
                // signal all nodes to perform initialization
                SIMIX_mutex_lock(smpi_global->start_stop_mutex);
@@ -97,13 +112,12 @@ void smpi_mpi_init()
                }
                SIMIX_mutex_unlock(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++;
        }
 
        // 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) {
+       if (smpi_global->ready_process_count < 3 * host_count) {
                SIMIX_cond_wait(smpi_global->start_stop_cond, smpi_global->start_stop_mutex);
        } else {
                SIMIX_cond_broadcast(smpi_global->start_stop_cond);
                SIMIX_cond_wait(smpi_global->start_stop_cond, smpi_global->start_stop_mutex);
        } else {
                SIMIX_cond_broadcast(smpi_global->start_stop_cond);
@@ -128,7 +142,7 @@ void smpi_mpi_finalize()
        if (0 >= i) {
 
                // wake up senders/receivers
        if (0 >= i) {
 
                // wake up senders/receivers
-               for (i = 0; i < smpi_mpi_global->mpi_comm_world->size; i++) {
+               for (i = 0; i < smpi_global->host_count; i++) {
                        if (SIMIX_process_is_suspended(smpi_global->sender_processes[i])) {
                                SIMIX_process_resume(smpi_global->sender_processes[i]);
                        }
                        if (SIMIX_process_is_suspended(smpi_global->sender_processes[i])) {
                                SIMIX_process_resume(smpi_global->sender_processes[i]);
                        }
@@ -139,7 +153,6 @@ void smpi_mpi_finalize()
 
                SIMIX_mutex_destroy(smpi_mpi_global->mpi_comm_world->barrier_mutex);
                SIMIX_cond_destroy(smpi_mpi_global->mpi_comm_world->barrier_cond);
 
                SIMIX_mutex_destroy(smpi_mpi_global->mpi_comm_world->barrier_mutex);
                SIMIX_cond_destroy(smpi_mpi_global->mpi_comm_world->barrier_cond);
-               xbt_free(smpi_mpi_global->mpi_comm_world->processes);
                xbt_free(smpi_mpi_global->mpi_comm_world);
 
                xbt_free(smpi_mpi_global->mpi_byte);
                xbt_free(smpi_mpi_global->mpi_comm_world);
 
                xbt_free(smpi_mpi_global->mpi_byte);
@@ -173,17 +186,17 @@ int smpi_mpi_barrier(smpi_mpi_communicator_t comm)
 int smpi_mpi_isend(smpi_mpi_request_t request)
 {
        int retval = MPI_SUCCESS;
 int smpi_mpi_isend(smpi_mpi_request_t request)
 {
        int retval = MPI_SUCCESS;
-       int rank   = smpi_mpi_comm_rank_self(smpi_mpi_global->mpi_comm_world);
+       int index  = smpi_host_index();
 
        if (NULL == request) {
                retval = MPI_ERR_INTERN;
        } else {
 
        if (NULL == request) {
                retval = MPI_ERR_INTERN;
        } else {
-               SIMIX_mutex_lock(smpi_global->pending_send_request_queues_mutexes[rank]);
-               xbt_fifo_push(smpi_global->pending_send_request_queues[rank], request);
-               SIMIX_mutex_unlock(smpi_global->pending_send_request_queues_mutexes[rank]);
+               SIMIX_mutex_lock(smpi_global->pending_send_request_queues_mutexes[index]);
+               xbt_fifo_push(smpi_global->pending_send_request_queues[index], request);
+               SIMIX_mutex_unlock(smpi_global->pending_send_request_queues_mutexes[index]);
 
 
-               if (SIMIX_process_is_suspended(smpi_global->sender_processes[rank])) {
-                       SIMIX_process_resume(smpi_global->sender_processes[rank]);
+               if (SIMIX_process_is_suspended(smpi_global->sender_processes[index])) {
+                       SIMIX_process_resume(smpi_global->sender_processes[index]);
                }
        }
 
                }
        }
 
@@ -193,17 +206,17 @@ int smpi_mpi_isend(smpi_mpi_request_t request)
 int smpi_mpi_irecv(smpi_mpi_request_t request)
 {
        int retval = MPI_SUCCESS;
 int smpi_mpi_irecv(smpi_mpi_request_t request)
 {
        int retval = MPI_SUCCESS;
-       int rank = smpi_mpi_comm_rank_self(smpi_mpi_global->mpi_comm_world);
+       int index = smpi_host_index();
 
        if (NULL == request) {
                retval = MPI_ERR_INTERN;
        } else {
 
        if (NULL == request) {
                retval = MPI_ERR_INTERN;
        } else {
-               SIMIX_mutex_lock(smpi_global->pending_recv_request_queues_mutexes[rank]);
-               xbt_fifo_push(smpi_global->pending_recv_request_queues[rank], request);
-               SIMIX_mutex_unlock(smpi_global->pending_recv_request_queues_mutexes[rank]);
+               SIMIX_mutex_lock(smpi_global->pending_recv_request_queues_mutexes[index]);
+               xbt_fifo_push(smpi_global->pending_recv_request_queues[index], request);
+               SIMIX_mutex_unlock(smpi_global->pending_recv_request_queues_mutexes[index]);
 
 
-               if (SIMIX_process_is_suspended(smpi_global->receiver_processes[rank])) {
-                       SIMIX_process_resume(smpi_global->receiver_processes[rank]);
+               if (SIMIX_process_is_suspended(smpi_global->receiver_processes[index])) {
+                       SIMIX_process_resume(smpi_global->receiver_processes[index]);
                }
        }
 
                }
        }
 
index 7f193c0..374ff97 100644 (file)
@@ -5,18 +5,18 @@
 
 void smpi_bench_begin()
 {
 
 void smpi_bench_begin()
 {
-       int rank = smpi_mpi_comm_rank_self(smpi_mpi_global->mpi_comm_world);
+       int index = smpi_host_index();
 
 
-       SIMIX_mutex_lock(smpi_global->timers_mutexes[rank]);
+       SIMIX_mutex_lock(smpi_global->timers_mutexes[index]);
 
 
-       xbt_os_timer_start(smpi_global->timers[rank]);
+       xbt_os_timer_start(smpi_global->timers[index]);
 
        return;
 }
 
 void smpi_bench_end()
 {
 
        return;
 }
 
 void smpi_bench_end()
 {
-       int rank = smpi_mpi_comm_rank_self(smpi_mpi_global->mpi_comm_world);
+       int index = smpi_host_index();
        double duration;
        smx_host_t host;
        char computation[] = "computation";
        double duration;
        smx_host_t host;
        char computation[] = "computation";
@@ -24,13 +24,13 @@ void smpi_bench_end()
        smx_mutex_t mutex;
        smx_cond_t cond;
 
        smx_mutex_t mutex;
        smx_cond_t cond;
 
-       xbt_os_timer_stop(smpi_global->timers[rank]);
+       xbt_os_timer_stop(smpi_global->timers[index]);
 
 
-       duration = xbt_os_timer_elapsed(smpi_global->timers[rank]);
+       duration = xbt_os_timer_elapsed(smpi_global->timers[index]);
 
 
-       SIMIX_mutex_unlock(smpi_global->timers_mutexes[rank]);
+       SIMIX_mutex_unlock(smpi_global->timers_mutexes[index]);
 
 
-       host   = smpi_mpi_global->mpi_comm_world->hosts[rank];
+       host   = smpi_global->hosts[index];
        action = SIMIX_action_execute(host, computation, duration * SMPI_DEFAULT_SPEED);
        mutex  = SIMIX_mutex_init();
        cond   = SIMIX_cond_init();
        action = SIMIX_action_execute(host, computation, duration * SMPI_DEFAULT_SPEED);
        mutex  = SIMIX_mutex_init();
        cond   = SIMIX_cond_init();
index ba2db8b..0d069d0 100644 (file)
@@ -129,9 +129,10 @@ void smpi_global_init()
        smpi_global->start_stop_mutex                    = SIMIX_mutex_init();
        smpi_global->start_stop_cond                     = SIMIX_cond_init();
 
        smpi_global->start_stop_mutex                    = SIMIX_mutex_init();
        smpi_global->start_stop_cond                     = SIMIX_cond_init();
 
-       // processes
-       smpi_global->sender_processes                    = xbt_new(smx_process_t, size);
-       smpi_global->receiver_processes                  = xbt_new(smx_process_t, size);
+       // host info blank until sim starts
+       // FIXME: is this okay?
+       smpi_global->hosts                               = NULL;
+       smpi_global->host_count                          = 0;
 
        // running hosts
        smpi_global->running_hosts_count_mutex           = SIMIX_mutex_init();
 
        // running hosts
        smpi_global->running_hosts_count_mutex           = SIMIX_mutex_init();
@@ -151,6 +152,10 @@ void smpi_global_init()
        smpi_global->received_message_queues             = xbt_new(xbt_fifo_t,  size);
        smpi_global->received_message_queues_mutexes     = xbt_new(smx_mutex_t, size);
 
        smpi_global->received_message_queues             = xbt_new(xbt_fifo_t,  size);
        smpi_global->received_message_queues_mutexes     = xbt_new(smx_mutex_t, size);
 
+       // sender/receiver processes
+       smpi_global->sender_processes                    = xbt_new(smx_process_t, size);
+       smpi_global->receiver_processes                  = xbt_new(smx_process_t, size);
+
        // timers
        smpi_global->timers                              = xbt_new(xbt_os_timer_t, size);
        smpi_global->timers_mutexes                      = xbt_new(smx_mutex_t, size);
        // timers
        smpi_global->timers                              = xbt_new(xbt_os_timer_t, size);
        smpi_global->timers_mutexes                      = xbt_new(smx_mutex_t, size);
@@ -214,6 +219,17 @@ void smpi_global_destroy()
        smpi_global = NULL;
 }
 
        smpi_global = NULL;
 }
 
+// FIXME: smarter algorithm?
+int smpi_host_index()
+{
+       int i;
+       smx_host_t host = SIMIX_host_self();
+
+       for(i = smpi_global->host_count - 1; i > 0 && host != smpi_global->hosts[i]; i--);
+
+       return i;
+}
+
 int smpi_run_simulation(int argc, char **argv)
 {
        xbt_fifo_item_t cond_item   = NULL;
 int smpi_run_simulation(int argc, char **argv)
 {
        xbt_fifo_item_t cond_item   = NULL;
index 201d1bd..102520e 100644 (file)
@@ -52,7 +52,7 @@ int MPI_Comm_rank(MPI_Comm comm, int *rank)
        } else if (NULL == rank) {
                retval = MPI_ERR_ARG;
        } else {
        } else if (NULL == rank) {
                retval = MPI_ERR_ARG;
        } else {
-               *rank = smpi_mpi_comm_rank_self(comm);
+               retval = smpi_mpi_comm_rank(comm, rank);
        }
 
        smpi_bench_begin();
        }
 
        smpi_bench_begin();
@@ -99,11 +99,11 @@ int MPI_Barrier(MPI_Comm comm)
 int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request *request)
 {
        int retval = MPI_SUCCESS;
 int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request *request)
 {
        int retval = MPI_SUCCESS;
-       int dst;
+       int dst = 0;
 
        smpi_bench_end();
 
 
        smpi_bench_end();
 
-       dst = smpi_mpi_comm_rank_self(comm);
+       //dst = smpi_mpi_comm_rank(comm);
        if (NULL == request) {
                retval = MPI_ERR_ARG;
        } else {
        if (NULL == request) {
                retval = MPI_ERR_ARG;
        } else {
@@ -121,12 +121,13 @@ int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI
 int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status)
 {
        int retval = MPI_SUCCESS;
 int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status)
 {
        int retval = MPI_SUCCESS;
-       int dst;
+       int dst = 0;
        smpi_mpi_request_t request;
 
        smpi_bench_end();
 
        smpi_mpi_request_t request;
 
        smpi_bench_end();
 
-       dst = smpi_mpi_comm_rank_self(comm);
+       // FIXME: necessary?
+       //dst = smpi_mpi_comm_rank(comm);
        retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, &request);
 
        if (NULL != request && MPI_SUCCESS == retval) {
        retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, &request);
 
        if (NULL != request && MPI_SUCCESS == retval) {
@@ -145,11 +146,11 @@ int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_
 int MPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request *request)
 {
        int retval = MPI_SUCCESS;
 int MPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request *request)
 {
        int retval = MPI_SUCCESS;
-       int src;
+       int src = 0;
 
        smpi_bench_end();
 
 
        smpi_bench_end();
 
-       src = smpi_mpi_comm_rank_self(comm);
+       //src = smpi_mpi_comm_rank(comm);
        if (NULL == request) {
                retval = MPI_ERR_ARG;
        } else {
        if (NULL == request) {
                retval = MPI_ERR_ARG;
        } else {
@@ -167,12 +168,12 @@ int MPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI
 int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
 {
        int retval = MPI_SUCCESS;
 int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
 {
        int retval = MPI_SUCCESS;
-       int src;
+       int src = 0;
        smpi_mpi_request_t request;
 
        smpi_bench_end();
 
        smpi_mpi_request_t request;
 
        smpi_bench_end();
 
-       src = smpi_mpi_comm_rank_self(comm);
+       //src = smpi_mpi_comm_rank(comm);
        retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, &request);
        if (NULL != request && MPI_SUCCESS == retval) {
                retval = smpi_mpi_isend(request);
        retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, &request);
        if (NULL != request && MPI_SUCCESS == retval) {
                retval = smpi_mpi_isend(request);
index 23d9cca..4c046f0 100644 (file)
@@ -3,12 +3,13 @@
 int smpi_receiver(int argc, char **argv)
 {
        smx_process_t self;
 int smpi_receiver(int argc, char **argv)
 {
        smx_process_t self;
-       int rank;
+       int index;
 
        xbt_fifo_t request_queue;
        smx_mutex_t request_queue_mutex;
        xbt_fifo_t message_queue;
        smx_mutex_t message_queue_mutex;
 
        xbt_fifo_t request_queue;
        smx_mutex_t request_queue_mutex;
        xbt_fifo_t message_queue;
        smx_mutex_t message_queue_mutex;
+       // FIXME: remove?  also sender
        int size;
 
        int running_hosts_count;
        int size;
 
        int running_hosts_count;
@@ -28,15 +29,15 @@ int smpi_receiver(int argc, char **argv)
        }
        SIMIX_mutex_unlock(smpi_global->start_stop_mutex);
 
        }
        SIMIX_mutex_unlock(smpi_global->start_stop_mutex);
 
-       rank = smpi_mpi_comm_rank_self(smpi_mpi_global->mpi_comm_world);
-       size = smpi_mpi_comm_size(smpi_mpi_global->mpi_comm_world);
+       index = smpi_host_index();
+       size  = smpi_global->host_count;
 
 
-       request_queue       = smpi_global->pending_recv_request_queues[rank];
-       request_queue_mutex = smpi_global->pending_recv_request_queues_mutexes[rank];
-       message_queue       = smpi_global->received_message_queues[rank];
-       message_queue_mutex = smpi_global->received_message_queues_mutexes[rank];
+       request_queue       = smpi_global->pending_recv_request_queues[index];
+       request_queue_mutex = smpi_global->pending_recv_request_queues_mutexes[index];
+       message_queue       = smpi_global->received_message_queues[index];
+       message_queue_mutex = smpi_global->received_message_queues_mutexes[index];
 
 
-       smpi_global->receiver_processes[rank] = self;
+       smpi_global->receiver_processes[index] = self;
 
        // wait for all nodes to signal initializatin complete
        SIMIX_mutex_lock(smpi_global->start_stop_mutex);
 
        // wait for all nodes to signal initializatin complete
        SIMIX_mutex_lock(smpi_global->start_stop_mutex);
index 7b3e609..23d4831 100644 (file)
@@ -4,7 +4,7 @@ int smpi_sender(int argc, char **argv)
 {
        smx_process_t self;
        smx_host_t shost;
 {
        smx_process_t self;
        smx_host_t shost;
-       int rank;
+       int index;
 
        xbt_fifo_t request_queue;
        smx_mutex_t request_queue_mutex;
 
        xbt_fifo_t request_queue;
        smx_mutex_t request_queue_mutex;
@@ -21,7 +21,7 @@ int smpi_sender(int argc, char **argv)
 
        smpi_received_message_t message;
 
 
        smpi_received_message_t message;
 
-       int drank;
+       int dindex;
 
        smx_process_t receiver_process;
 
 
        smx_process_t receiver_process;
 
@@ -35,13 +35,13 @@ int smpi_sender(int argc, char **argv)
        }
        SIMIX_mutex_unlock(smpi_global->start_stop_mutex);
 
        }
        SIMIX_mutex_unlock(smpi_global->start_stop_mutex);
 
-       rank = smpi_mpi_comm_rank(smpi_mpi_global->mpi_comm_world, shost);
-       size = smpi_mpi_comm_size(smpi_mpi_global->mpi_comm_world);
+       index = smpi_host_index();
+       size  = smpi_global->host_count;
 
 
-       request_queue       = smpi_global->pending_send_request_queues[rank];
-       request_queue_mutex = smpi_global->pending_send_request_queues_mutexes[rank];
+       request_queue       = smpi_global->pending_send_request_queues[index];
+       request_queue_mutex = smpi_global->pending_send_request_queues_mutexes[index];
 
 
-       smpi_global->sender_processes[rank] = self;
+       smpi_global->sender_processes[index] = self;
 
        // wait for all nodes to signal initializatin complete
        SIMIX_mutex_lock(smpi_global->start_stop_mutex);
 
        // wait for all nodes to signal initializatin complete
        SIMIX_mutex_lock(smpi_global->start_stop_mutex);
@@ -68,18 +68,18 @@ int smpi_sender(int argc, char **argv)
                        SIMIX_mutex_lock(request->mutex);
 
                        message->comm = request->comm;
                        SIMIX_mutex_lock(request->mutex);
 
                        message->comm = request->comm;
-                       message->src  = request->src;
-                       message->dst  = request->dst;
+                       // FIXME: maybe we don't need this map 
+                       message->src  = request->comm->index_to_rank_map[index];
                        message->tag  = request->tag;
                        message->buf  = xbt_malloc(request->datatype->size * request->count);
                        memcpy(message->buf, request->buf, request->datatype->size * request->count);
 
                        message->tag  = request->tag;
                        message->buf  = xbt_malloc(request->datatype->size * request->count);
                        memcpy(message->buf, request->buf, request->datatype->size * request->count);
 
-                       dhost = request->comm->hosts[request->dst];
-                       drank = smpi_mpi_comm_rank(smpi_mpi_global->mpi_comm_world, dhost);
+                       dindex = request->comm->rank_to_index_map[request->dst];
+                       dhost  = smpi_global->hosts[dindex];
 
 
-                       SIMIX_mutex_lock(smpi_global->received_message_queues_mutexes[drank]);
-                       xbt_fifo_push(smpi_global->received_message_queues[drank], message);
-                       SIMIX_mutex_unlock(smpi_global->received_message_queues_mutexes[drank]);
+                       SIMIX_mutex_lock(smpi_global->received_message_queues_mutexes[dindex]);
+                       xbt_fifo_push(smpi_global->received_message_queues[dindex], message);
+                       SIMIX_mutex_unlock(smpi_global->received_message_queues_mutexes[dindex]);
 
                        request->completed = 1;
 
 
                        request->completed = 1;
 
@@ -94,7 +94,7 @@ int smpi_sender(int argc, char **argv)
                        //SIMIX_action_destroy(action);
 
                        // wake up receiver if necessary
                        //SIMIX_action_destroy(action);
 
                        // wake up receiver if necessary
-                       receiver_process = smpi_global->receiver_processes[drank];
+                       receiver_process = smpi_global->receiver_processes[dindex];
                        if (SIMIX_process_is_suspended(receiver_process)) {
                                SIMIX_process_resume(receiver_process);
                        }
                        if (SIMIX_process_is_suspended(receiver_process)) {
                                SIMIX_process_resume(receiver_process);
                        }