Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
renamed some functions and moved some data structures to make things more
authormarkls <markls@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 4 Sep 2007 10:55:55 +0000 (10:55 +0000)
committermarkls <markls@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 4 Sep 2007 10:55:55 +0000 (10:55 +0000)
consistent.

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@4134 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

index 5d08141..da7560a 100644 (file)
@@ -12,6 +12,7 @@
 #define SMPI_REQUEST_MALLOCATOR_SIZE 100
 #define SMPI_MESSAGE_MALLOCATOR_SIZE 100
 
+// smpi mpi communicator
 typedef struct smpi_mpi_communicator_t {
        int            size;
        smx_host_t    *hosts;
@@ -21,6 +22,12 @@ typedef struct smpi_mpi_communicator_t {
        smx_cond_t     barrier_cond;
 } s_smpi_mpi_communicator_t;
 
+// smpi mpi datatype
+typedef struct smpi_mpi_datatype_t {
+  size_t size;
+} s_smpi_mpi_datatype_t;
+
+// smpi mpi request
 typedef struct smpi_mpi_request_t {
        smpi_mpi_communicator_t comm;
        int src;
@@ -37,7 +44,22 @@ typedef struct smpi_mpi_request_t {
        smx_cond_t  cond;
 } s_smpi_mpi_request_t;
 
-typedef struct SMPI_Global {
+// smpi mpi op
+typedef struct smpi_mpi_op_t {
+  void (*func)(void *x, void *y, void *z);
+} s_smpi_mpi_op_t;
+
+// smpi received message
+typedef struct smpi_received_message_t {
+       smpi_mpi_communicator_t comm;
+       int src;
+       int dst;
+       int tag;
+       void *buf;
+} s_smpi_received_message_t;
+typedef struct smpi_received_message_t *smpi_received_message_t;
+
+typedef struct smpi_global_t {
 
        // config vars
        double            reference_speed;
@@ -69,45 +91,33 @@ typedef struct SMPI_Global {
        xbt_os_timer_t   *timers;
        smx_mutex_t      *timers_mutexes;
 
-} s_SMPI_Global_t, *SMPI_Global_t;
-extern SMPI_Global_t smpi_global;
-
-typedef struct smpi_received_message_t {
-       smpi_mpi_communicator_t comm;
-       int src;
-       int dst;
-       int tag;
-       void *buf;
-} s_smpi_received_message_t;
-typedef struct smpi_received_message_t *smpi_received_message_t;
+} s_smpi_global_t;
+typedef struct smpi_global_t *smpi_global_t;
+extern smpi_global_t smpi_global;
 
 // 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_sender(int argc, char **argv);
-int smpi_receiver(int argc, char **argv);
-void *smpi_request_new(void);
-void smpi_request_free(void *pointer);
-void smpi_request_reset(void *pointer);
-void *smpi_message_new(void);
-void smpi_message_free(void *pointer);
-void smpi_message_reset(void *pointer);
+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_wait(smpi_mpi_request_t request, smpi_mpi_status_t *status);
+
+void smpi_bench_begin(void);
+void smpi_bench_end(void);
+
 void smpi_global_init(void);
 void smpi_global_destroy(void);
 int smpi_run_simulation(int argc, char **argv);
-void smpi_mpi_land_func(void *x, void *y, void *z);
-void smpi_mpi_sum_func(void *x, void *y, void *z);
-void smpi_mpi_init(void);
-void smpi_mpi_finalize(void);
-void smpi_bench_begin(void);
-void smpi_bench_end(void);
-void smpi_barrier(smpi_mpi_communicator_t comm);
 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_isend(smpi_mpi_request_t request);
-int smpi_irecv(smpi_mpi_request_t request);
-int smpi_wait(smpi_mpi_request_t request, smpi_mpi_status_t *status);
+
+int smpi_sender(int argc, char **argv);
+
+int smpi_receiver(int argc, char **argv);
 
 #endif
index 7f0fd9d..8d64b45 100644 (file)
@@ -1,12 +1,16 @@
 #include "private.h"
 
-SMPI_MPI_Global_t smpi_mpi_global = NULL;
+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 *x, void *y, void *z)
 {
        *(int *)z = *(int *)x && *(int *)y;
 }
 
+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;
@@ -52,7 +56,7 @@ void smpi_mpi_init()
        // node 0 sets the globals
        if (host == hosts[0]) {
 
-               smpi_mpi_global                                = xbt_new(s_SMPI_MPI_Global_t, 1);
+               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);
@@ -151,7 +155,7 @@ void smpi_mpi_finalize()
 
 }
 
-void smpi_barrier(smpi_mpi_communicator_t comm)
+int smpi_mpi_barrier(smpi_mpi_communicator_t comm)
 {
 
        SIMIX_mutex_lock(comm->barrier_mutex);
@@ -163,91 +167,67 @@ void smpi_barrier(smpi_mpi_communicator_t comm)
        }
        SIMIX_mutex_unlock(comm->barrier_mutex);
 
-       return;
+       return MPI_SUCCESS;
 }
 
-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_mpi_isend(smpi_mpi_request_t request)
 {
        int retval = MPI_SUCCESS;
+       int rank   = smpi_mpi_comm_rank_self(smpi_mpi_global->mpi_comm_world);
 
-       *request = NULL;
-
-       if (0 > count) {
-               retval = MPI_ERR_COUNT;
-       } else if (NULL == buf) {
+       if (NULL == request) {
                retval = MPI_ERR_INTERN;
-       } else if (NULL == datatype) {
-               retval = MPI_ERR_TYPE;
-       } else if (NULL == comm) {
-               retval = MPI_ERR_COMM;
-       } else if (MPI_ANY_SOURCE != src && (0 > src || comm->size <= src)) {
-               retval = MPI_ERR_RANK;
-       } else if (0 > dst || comm->size <= dst) {
-               retval = MPI_ERR_RANK;
-       } else if (0 > tag) {
-               retval = MPI_ERR_TAG;
        } else {
-               *request               = xbt_mallocator_get(smpi_global->request_mallocator);
-               (*request)->comm       = comm;
-               (*request)->src        = src;
-               (*request)->dst        = dst;
-               (*request)->tag        = tag;
-               (*request)->buf        = buf;
-               (*request)->count      = count;
-               (*request)->datatype   = datatype;
-       }
-       return retval;
-}
-
-int smpi_isend(smpi_mpi_request_t request)
-{
-       int retval = MPI_SUCCESS;
-       int rank   = smpi_mpi_comm_rank_self(smpi_mpi_global->mpi_comm_world);
-
-       if (NULL != request) {
                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]);
-       }
 
-       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[rank])) {
+                       SIMIX_process_resume(smpi_global->sender_processes[rank]);
+               }
        }
 
        return retval;
 }
 
-int smpi_irecv(smpi_mpi_request_t request)
+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);
 
-       if (NULL != request) {
+       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]);
-       }
 
-       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[rank])) {
+                       SIMIX_process_resume(smpi_global->receiver_processes[rank]);
+               }
        }
 
        return retval;
 }
 
-int smpi_wait(smpi_mpi_request_t request, smpi_mpi_status_t *status)
+int smpi_mpi_wait(smpi_mpi_request_t request, smpi_mpi_status_t *status)
 {
-       if (NULL != request) {
+       int retval = MPI_SUCCESS;
+
+       if (NULL == request) {
+               retval = MPI_ERR_INTERN;
+       } else {
                SIMIX_mutex_lock(request->mutex);
                if (!request->completed) {
                        SIMIX_cond_wait(request->cond, request->mutex);
                }
                if (NULL != status) {
                        status->MPI_SOURCE = request->src;
+                       status->MPI_TAG    = request->tag;
+                       status->MPI_ERROR  = MPI_SUCCESS;
                }
                SIMIX_mutex_unlock(request->mutex);
        }
 
-       return MPI_SUCCESS;
+       return retval;
 }
index 73a3445..7f193c0 100644 (file)
@@ -1,6 +1,8 @@
 #include "private.h"
 
 // FIXME: could cause trouble with multithreaded procs on same host...
+// FIXME: add benchmarking flag?
+
 void smpi_bench_begin()
 {
        int rank = smpi_mpi_comm_rank_self(smpi_mpi_global->mpi_comm_world);
index 24d7974..ba2db8b 100644 (file)
@@ -4,7 +4,9 @@
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi, XBT_LOG_ROOT_CAT, "All SMPI categories");
 
-SMPI_Global_t     smpi_global     = NULL;
+smpi_global_t     smpi_global     = NULL;
+
+void *smpi_request_new(void);
 
 void *smpi_request_new()
 {
@@ -17,6 +19,8 @@ void *smpi_request_new()
        return request;
 }
 
+void smpi_request_free(void *pointer);
+
 void smpi_request_free(void *pointer)
 {
 
@@ -31,6 +35,8 @@ void smpi_request_free(void *pointer)
        return;
 }
 
+void smpi_request_reset(void *pointer);
+
 void smpi_request_reset(void *pointer)
 {
        smpi_mpi_request_t request = pointer;
@@ -41,11 +47,15 @@ void smpi_request_reset(void *pointer)
 }
 
 
+void *smpi_message_new(void);
+
 void *smpi_message_new()
 {
        return xbt_new(s_smpi_received_message_t, 1);
 }
 
+void smpi_message_free(void *pointer);
+
 void smpi_message_free(void *pointer)
 {
        if (NULL != pointer) {
@@ -55,18 +65,59 @@ void smpi_message_free(void *pointer)
        return;
 }
 
+void smpi_message_reset(void *pointer);
+
 void smpi_message_reset(void *pointer)
 {
        return;
 }
 
+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 *requestptr)
+{
+       int retval = MPI_SUCCESS;
+
+       smpi_mpi_request_t request = NULL;
+
+       // FIXME: make sure requestptr is not null
+       if (NULL == buf) {
+               retval = MPI_ERR_INTERN;
+       } else if (0 > count) {
+               retval = MPI_ERR_COUNT;
+       } else if (NULL == datatype) {
+               retval = MPI_ERR_TYPE;
+       } else if (MPI_ANY_SOURCE != src && (0 > src || comm->size <= src)) {
+               retval = MPI_ERR_RANK;
+       } else if (0 > dst || comm->size <= dst) {
+               retval = MPI_ERR_RANK;
+       } else if (MPI_ANY_TAG != tag && 0 > tag) {
+               retval = MPI_ERR_TAG;
+       } else if (NULL == comm) {
+               retval = MPI_ERR_COMM;
+       } else if (NULL == requestptr) {
+               retval = MPI_ERR_INTERN;
+       } else {
+               request           = xbt_mallocator_get(smpi_global->request_mallocator);
+               request->comm     = comm;
+               request->src      = src;
+               request->dst      = dst;
+               request->tag      = tag;
+               request->buf      = buf;
+               request->datatype = datatype;
+               request->count    = count;
+
+               *requestptr       = request;
+       }
+       return retval;
+}
+
 void smpi_global_init()
 {
        int i;
 
        int size = SIMIX_host_get_number();
 
-       smpi_global                                      = xbt_new(s_SMPI_Global_t, 1);
+       smpi_global                                      = xbt_new(s_smpi_global_t, 1);
 
        // config variable
        smpi_global->reference_speed                     = SMPI_DEFAULT_SPEED;
index fe412d3..201d1bd 100644 (file)
@@ -19,7 +19,6 @@ int MPI_Finalize()
 int MPI_Abort(MPI_Comm comm, int errorcode)
 {
        smpi_exit(errorcode);
-
        return 0;
 }
 
@@ -53,7 +52,7 @@ int MPI_Comm_rank(MPI_Comm comm, int *rank)
        } else if (NULL == rank) {
                retval = MPI_ERR_ARG;
        } else {
-               *rank = smpi_mpi_comm_rank(comm, SIMIX_host_self());
+               *rank = smpi_mpi_comm_rank_self(comm);
        }
 
        smpi_bench_begin();
@@ -80,26 +79,42 @@ int MPI_Type_size(MPI_Datatype datatype, size_t *size)
        return retval;
 }
 
-// FIXME: check comm value and barrier success...
 int MPI_Barrier(MPI_Comm comm)
 {
+       int retval = MPI_SUCCESS;
+
        smpi_bench_end();
-       smpi_barrier(comm);
+
+       if (NULL == comm) {
+               retval = MPI_ERR_COMM;
+       } else {
+               retval = smpi_mpi_barrier(comm);
+       }
+
        smpi_bench_begin();
-       return MPI_SUCCESS;
+
+       return retval;
 }
 
 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;
+
        smpi_bench_end();
+
        dst = smpi_mpi_comm_rank_self(comm);
-       retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, request);
-       if (NULL != *request && MPI_SUCCESS == retval) {
-               retval = smpi_irecv(*request);
+       if (NULL == request) {
+               retval = MPI_ERR_ARG;
+       } else {
+               retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, request);
+               if (NULL != *request && MPI_SUCCESS == retval) {
+                       retval = smpi_mpi_irecv(*request);
+               }
        }
+
        smpi_bench_begin();
+
        return retval;
 }
 
@@ -108,19 +123,22 @@ int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_
        int retval = MPI_SUCCESS;
        int dst;
        smpi_mpi_request_t request;
-       int rank;
+
        smpi_bench_end();
+
        dst = smpi_mpi_comm_rank_self(comm);
        retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, &request);
+
        if (NULL != request && MPI_SUCCESS == retval) {
-               retval = smpi_irecv(request);
+               retval = smpi_mpi_irecv(request);
                if (MPI_SUCCESS == retval) {
-                       retval = smpi_wait(request, status);
+                       retval = smpi_mpi_wait(request, status);
                }
-               rank = smpi_mpi_comm_rank_self(smpi_mpi_global->mpi_comm_world);
                xbt_mallocator_release(smpi_global->request_mallocator, request);
        }
+
        smpi_bench_begin();
+
        return retval;
 }
 
@@ -128,13 +146,21 @@ int MPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI
 {
        int retval = MPI_SUCCESS;
        int src;
+
        smpi_bench_end();
+
        src = smpi_mpi_comm_rank_self(comm);
-       retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, request);
-       if (NULL != *request && MPI_SUCCESS == retval) {
-               retval = smpi_isend(*request);
+       if (NULL == request) {
+               retval = MPI_ERR_ARG;
+       } else {
+               retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, request);
+               if (NULL != *request && MPI_SUCCESS == retval) {
+                       retval = smpi_mpi_isend(*request);
+               }
        }
+
        smpi_bench_begin();
+
        return retval;
 }
 
@@ -143,18 +169,20 @@ int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_
        int retval = MPI_SUCCESS;
        int src;
        smpi_mpi_request_t request;
-       int rank;
+
        smpi_bench_end();
+
        src = smpi_mpi_comm_rank_self(comm);
        retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, &request);
        if (NULL != request && MPI_SUCCESS == retval) {
-               retval = smpi_isend(request);
+               retval = smpi_mpi_isend(request);
                if (MPI_SUCCESS == retval) {
-                       smpi_wait(request, MPI_STATUS_IGNORE);
+                       smpi_mpi_wait(request, MPI_STATUS_IGNORE);
                }
-               rank = smpi_mpi_comm_rank_self(smpi_mpi_global->mpi_comm_world);
                xbt_mallocator_release(smpi_global->request_mallocator, request);
        }
+
        smpi_bench_begin();
+
        return retval;
 }
index bd1d1d9..23d9cca 100644 (file)
@@ -66,8 +66,8 @@ int smpi_receiver(int argc, char **argv)
                                message_item = xbt_fifo_get_next_item(message_item)) {
                                message = xbt_fifo_get_item_content(message_item);
                                if (request->comm == message->comm &&
-                                               (MPI_ANY_SOURCE == request->src || request->src == message->src) &&
-                                               request->tag == message->tag) {
+                                  (MPI_ANY_SOURCE == request->src || request->src == message->src) &&
+                                  (MPI_ANY_TAG == request->tag || request->tag == message->tag)) {
                                        xbt_fifo_remove_item(request_queue, request_item);
                                        xbt_fifo_remove_item(message_queue, message_item);
                                        goto stopsearch;