Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
used host user data to store global index values and remove some clunky
authormarkls <markls@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sun, 9 Sep 2007 04:05:24 +0000 (04:05 +0000)
committermarkls <markls@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sun, 9 Sep 2007 04:05:24 +0000 (04:05 +0000)
algorithms.

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@4142 48e7efb5-ca39-0410-a469-dd3cf9ba447f

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
src/smpi/smpi_util.c

index 804ea9e..6a6a436 100644 (file)
@@ -47,10 +47,8 @@ typedef struct smpi_mpi_request_t {
 } 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);
+  void (*func)(void *a, void *b, int *length, MPI_Datatype *datatype);
 } s_smpi_mpi_op_t;
 
 // smpi received message
@@ -101,11 +99,16 @@ typedef struct smpi_global_t {
 typedef struct smpi_global_t *smpi_global_t;
 extern smpi_global_t smpi_global;
 
+typedef struct smpi_host_data_t {
+       int index;
+} s_smpi_host_data_t;
+typedef struct smpi_host_data_t *smpi_host_data_t;
+
 // function prototypes
 void smpi_mpi_init(void);
 void smpi_mpi_finalize(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_comm_rank(smpi_mpi_communicator_t comm);
+
 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);
index bb266ea..10f8303 100644 (file)
@@ -2,48 +2,35 @@
 
 smpi_mpi_global_t smpi_mpi_global = NULL;
 
-void smpi_mpi_land_func(void *x, void *y, void *z);
+void smpi_mpi_land_func(void *a, void *b, int *length, MPI_Datatype *datatype);
 
-void smpi_mpi_land_func(void *x, void *y, void *z)
+void smpi_mpi_land_func(void *a, void *b, int *length, MPI_Datatype *datatype)
 {
-       *(int *)z = *(int *)x && *(int *)y;
+       int i;
+       if (*datatype == smpi_mpi_global->mpi_int) {
+               int *x = a, *y = b;
+               for (i = 0; i < *length; i++) {
+                       y[i] = x[i] && y[i];
+               }
+       }
 }
 
-void smpi_mpi_sum_func(void *x, void *y, void *z);
-
-void smpi_mpi_sum_func(void *x, void *y, void *z)
-{
-       *(int *)z = *(int *)x + *(int *)y;
-}
+void smpi_mpi_sum_func(void *a, void *b, int *length, MPI_Datatype *datatype);
 
-int inline smpi_mpi_comm_size(smpi_mpi_communicator_t comm, int *size)
+void smpi_mpi_sum_func(void *a, void *b, int *length, MPI_Datatype *datatype)
 {
-       int retval = MPI_SUCCESS;
-       if (NULL == size) {
-               retval = MPI_ERR_ARG;
-       } else {
-               *size = comm->size;
+       int i;
+       if (*datatype == smpi_mpi_global->mpi_int) {
+               int *x = a, *y = b;
+               for (i = 0; i < *length; i++) {
+                       y[i] = x[i] + y[i];
+               }
        }
-       return retval;
 }
 
-// FIXME: smarter algorithm?
-int smpi_mpi_comm_rank(smpi_mpi_communicator_t comm, int *rank)
+int inline smpi_mpi_comm_rank(smpi_mpi_communicator_t comm)
 {
-       int i;
-       int retval = MPI_SUCCESS;
-
-       if (NULL == rank) {
-               retval = MPI_ERR_ARG;
-       } else {
-               smx_host_t host = SIMIX_host_self();
-
-               for (i = 0; i < comm->size && host != smpi_global->hosts[comm->rank_to_index_map[i]]; i++);
-
-               *rank = i;
-       }
-
-       return retval;
+       return comm->index_to_rank_map[smpi_host_index()];
 }
 
 void smpi_mpi_init()
@@ -52,6 +39,7 @@ void smpi_mpi_init()
        smx_host_t *hosts;
        int host_count;
        int i;
+       smpi_host_data_t hdata;
 
        SIMIX_mutex_lock(smpi_global->running_hosts_count_mutex);
        smpi_global->running_hosts_count++;
@@ -62,8 +50,16 @@ void smpi_mpi_init()
        hosts      = SIMIX_host_get_table();
        host_count = SIMIX_host_get_number();
 
+       hdata      = xbt_new(s_smpi_host_data_t, 1);
+
+       for (i = 0; i < host_count && host != hosts[i]; i ++);
+
+       hdata->index = i;
+
+       SIMIX_host_set_data(host, hdata);
+
        // node 0 sets the globals
-       if (host == hosts[0]) {
+       if (0 == i) {
 
                smpi_global->hosts                              = hosts;
                smpi_global->host_count                         = host_count;
index 374ff97..9bd1f19 100644 (file)
@@ -45,7 +45,5 @@ void smpi_bench_end()
        SIMIX_cond_destroy(cond);
        //SIMIX_action_destroy(action);
 
-       // FIXME: check for success/failure?
-
        return;
 }
index 0d069d0..dfac6a6 100644 (file)
@@ -219,15 +219,12 @@ void smpi_global_destroy()
        smpi_global = NULL;
 }
 
-// FIXME: smarter algorithm?
 int smpi_host_index()
 {
-       int i;
        smx_host_t host = SIMIX_host_self();
+       smpi_host_data_t hdata = (smpi_host_data_t)SIMIX_host_get_data(host);
 
-       for(i = smpi_global->host_count - 1; i > 0 && host != smpi_global->hosts[i]; i--);
-
-       return i;
+       return hdata->index;
 }
 
 int smpi_run_simulation(int argc, char **argv)
index 102520e..c378d86 100644 (file)
@@ -52,7 +52,7 @@ int MPI_Comm_rank(MPI_Comm comm, int *rank)
        } else if (NULL == rank) {
                retval = MPI_ERR_ARG;
        } else {
-               retval = smpi_mpi_comm_rank(comm, rank);
+               *rank = smpi_mpi_comm_rank(comm);
        }
 
        smpi_bench_begin();
@@ -99,14 +99,13 @@ 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 dst = 0;
 
        smpi_bench_end();
 
-       //dst = smpi_mpi_comm_rank(comm);
        if (NULL == request) {
                retval = MPI_ERR_ARG;
        } else {
+               int dst = 0;
                retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, request);
                if (NULL != *request && MPI_SUCCESS == retval) {
                        retval = smpi_mpi_irecv(*request);
@@ -126,10 +125,7 @@ int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_
 
        smpi_bench_end();
 
-       // 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_mpi_irecv(request);
                if (MPI_SUCCESS == retval) {
@@ -146,14 +142,13 @@ 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 src = 0;
 
        smpi_bench_end();
 
-       //src = smpi_mpi_comm_rank(comm);
        if (NULL == request) {
                retval = MPI_ERR_ARG;
        } else {
+               int src = 0;
                retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, request);
                if (NULL != *request && MPI_SUCCESS == retval) {
                        retval = smpi_mpi_isend(*request);
@@ -173,7 +168,6 @@ int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_
 
        smpi_bench_end();
 
-       //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);
index 4c046f0..283e5f2 100644 (file)
@@ -9,8 +9,6 @@ int smpi_receiver(int argc, char **argv)
        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;
 
@@ -30,7 +28,6 @@ int smpi_receiver(int argc, char **argv)
        SIMIX_mutex_unlock(smpi_global->start_stop_mutex);
 
        index = smpi_host_index();
-       size  = smpi_global->host_count;
 
        request_queue       = smpi_global->pending_recv_request_queues[index];
        request_queue_mutex = smpi_global->pending_recv_request_queues_mutexes[index];
@@ -42,7 +39,7 @@ int smpi_receiver(int argc, char **argv)
        // 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 * smpi_global->host_count) {
                SIMIX_cond_wait(smpi_global->start_stop_cond, smpi_global->start_stop_mutex);
        } else {
                SIMIX_cond_broadcast(smpi_global->start_stop_cond);
index 23d4831..5715058 100644 (file)
@@ -8,7 +8,6 @@ int smpi_sender(int argc, char **argv)
 
        xbt_fifo_t request_queue;
        smx_mutex_t request_queue_mutex;
-       int size;
 
        int running_hosts_count;
 
@@ -36,7 +35,6 @@ int smpi_sender(int argc, char **argv)
        SIMIX_mutex_unlock(smpi_global->start_stop_mutex);
 
        index = smpi_host_index();
-       size  = smpi_global->host_count;
 
        request_queue       = smpi_global->pending_send_request_queues[index];
        request_queue_mutex = smpi_global->pending_send_request_queues_mutexes[index];
@@ -46,7 +44,7 @@ int smpi_sender(int argc, char **argv)
        // 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 * smpi_global->host_count) {
                SIMIX_cond_wait(smpi_global->start_stop_cond, smpi_global->start_stop_mutex);
        } else {
                SIMIX_cond_broadcast(smpi_global->start_stop_cond);
@@ -68,8 +66,7 @@ int smpi_sender(int argc, char **argv)
                        SIMIX_mutex_lock(request->mutex);
 
                        message->comm = request->comm;
-                       // FIXME: maybe we don't need this map 
-                       message->src  = request->comm->index_to_rank_map[index];
+                       message->src  = smpi_mpi_comm_rank(request->comm);
                        message->tag  = request->tag;
                        message->buf  = xbt_malloc(request->datatype->size * request->count);
                        memcpy(message->buf, request->buf, request->datatype->size * request->count);
index 60f4157..59518a2 100644 (file)
@@ -39,8 +39,6 @@ unsigned int smpi_sleep(unsigned int seconds)
        SIMIX_cond_destroy(cond);
        //SIMIX_action_destroy(action);
 
-       // FIXME: check for success/failure?
-
        smpi_bench_begin();
        return 0;
 }