Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
renamed MPI_ functions to avoid namespace collisions in distributed code.
authormarkls <markls@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 27 Nov 2007 11:34:36 +0000 (11:34 +0000)
committermarkls <markls@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 27 Nov 2007 11:34:36 +0000 (11:34 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5067 48e7efb5-ca39-0410-a469-dd3cf9ba447f

include/smpi/smpi.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 0566736..d5ef3c1 100644 (file)
@@ -1,9 +1,13 @@
 #ifndef SMPI_H
 #define SMPI_H
 
 #ifndef SMPI_H
 #define SMPI_H
 
+#include <stddef.h>
 #include <sys/time.h>
 #include <sys/time.h>
+#include <xbt/misc.h>
 #include <xbt/function_types.h>
 
 #include <xbt/function_types.h>
 
+SG_BEGIN_DECL()
+
 #define SMPI_RAND_SEED 5
 
 #define MPI_ANY_SOURCE -1
 #define SMPI_RAND_SEED 5
 
 #define MPI_ANY_SOURCE -1
@@ -76,30 +80,48 @@ extern smpi_mpi_global_t smpi_mpi_global;
 #define MPI_LAND          (smpi_mpi_global->mpi_land)
 #define MPI_SUM           (smpi_mpi_glboal->mpi_sum)
 
 #define MPI_LAND          (smpi_mpi_global->mpi_land)
 #define MPI_SUM           (smpi_mpi_glboal->mpi_sum)
 
-// MPI Functions
-int MPI_Init(int *argc, char ***argv);
-int MPI_Finalize(void);
-int MPI_Abort(MPI_Comm comm, int errorcode);
-int MPI_Comm_size(MPI_Comm comm, int *size);
-int MPI_Comm_rank(MPI_Comm comm, int *rank);
-int MPI_Type_size(MPI_Datatype datatype, size_t *size);
-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 MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status);
-int MPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request *request);
-int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm);
-int MPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm);
-int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *comm_out);
+// MPI macros
+#define MPI_Init(a, b) SMPI_MPI_Init(a, b)
+#define MPI_Finalize() SMPI_MPI_Finalize()
+#define MPI_Abort(a, b) SMPI_MPI_Abort(a, b)
+#define MPI_Comm_size(a, b) SMPI_MPI_Comm_size(a, b)
+#define MPI_Comm_rank(a, b) SMPI_MPI_Comm_rank(a, b)
+#define MPI_Type_size(a, b) SMPI_MPI_Type_size(a, b)
+#define MPI_Barrier(a) SMPI_MPI_Barrier(a)
+#define MPI_Irecv(a, b, c, d, e, f, g) SMPI_MPI_Irecv(a, b, c, d, e, f, g)
+#define MPI_Recv(a, b, c, d, e, f, g) SMPI_MPI_Recv(a, b, c, d, e, f, g)
+#define MPI_Isend(a, b, c, d, e, f, g) SMPI_MPI_Isend(a, b, c, d, e, f, g)
+#define MPI_Send(a, b, c, d, e, f) SMPI_MPI_Send(a, b, c, d, e, f)
+#define MPI_Bcast(a, b, c, d, e) SMPI_MPI_Bcast(a, b, c, d, e)
+#define MPI_Comm_split(a, b, c, d) SMPI_MPI_Comm_split(a, b, c, d)
+
+// SMPI Functions
+XBT_PUBLIC(int) SMPI_MPI_Init(int *argc, char ***argv);
+XBT_PUBLIC(int) SMPI_MPI_Finalize(void);
+XBT_PUBLIC(int) SMPI_MPI_Abort(MPI_Comm comm, int errorcode);
+XBT_PUBLIC(int) SMPI_MPI_Comm_size(MPI_Comm comm, int *size);
+XBT_PUBLIC(int) SMPI_MPI_Comm_rank(MPI_Comm comm, int *rank);
+XBT_PUBLIC(int) SMPI_MPI_Type_size(MPI_Datatype datatype, size_t *size);
+XBT_PUBLIC(int) SMPI_MPI_Barrier(MPI_Comm comm);
+XBT_PUBLIC(int) SMPI_MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request *request);
+XBT_PUBLIC(int) SMPI_MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status);
+XBT_PUBLIC(int) SMPI_MPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request *request);
+XBT_PUBLIC(int) SMPI_MPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm);
+XBT_PUBLIC(int) SMPI_MPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm);
+XBT_PUBLIC(int) SMPI_MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *comm_out);
 
 // smpi functions
 XBT_IMPORT_NO_EXPORT(int) smpi_simulated_main(int argc, char **argv);
 
 // smpi functions
 XBT_IMPORT_NO_EXPORT(int) smpi_simulated_main(int argc, char **argv);
-unsigned int smpi_sleep(unsigned int);
-void smpi_exit(int);
-int smpi_gettimeofday(struct timeval *tv, struct timezone *tz);
+XBT_PUBLIC(unsigned int) smpi_sleep(unsigned int);
+XBT_PUBLIC(void) smpi_exit(int);
+XBT_PUBLIC(int) smpi_gettimeofday(struct timeval *tv, struct timezone *tz);
+
+XBT_PUBLIC(void) smpi_do_once_1(const char *file, int line);
+XBT_PUBLIC(int)  smpi_do_once_2(void);
+XBT_PUBLIC(void) smpi_do_once_3(void);
 
 
-void smpi_do_once_1(const char *file, int line);
-int  smpi_do_once_2(void);
-void smpi_do_once_3(void);
 #define SMPI_DO_ONCE for (smpi_do_once_1(__FILE__, __LINE__); smpi_do_once_2(); smpi_do_once_3())
 
 #define SMPI_DO_ONCE for (smpi_do_once_1(__FILE__, __LINE__); smpi_do_once_2(); smpi_do_once_3())
 
+SG_END_DECL()
+
 #endif
 #endif
index 62834b6..3fcfc25 100644 (file)
@@ -1,5 +1,7 @@
 #include "private.h"
 
 #include "private.h"
 
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_base, smpi, "Logging specific to SMPI (base)");
+
 smpi_mpi_global_t smpi_mpi_global = NULL;
 
 void smpi_mpi_land_func(void *a, void *b, int *length, MPI_Datatype *datatype);
 smpi_mpi_global_t smpi_mpi_global = NULL;
 
 void smpi_mpi_land_func(void *a, void *b, int *length, MPI_Datatype *datatype);
@@ -28,7 +30,7 @@ void smpi_mpi_sum_func(void *a, void *b, int *length, MPI_Datatype *datatype)
        }
 }
 
        }
 }
 
-int inline smpi_mpi_comm_rank(smpi_mpi_communicator_t comm)
+int smpi_mpi_comm_rank(smpi_mpi_communicator_t comm)
 {
        return comm->index_to_rank_map[smpi_host_index()];
 }
 {
        return comm->index_to_rank_map[smpi_host_index()];
 }
@@ -103,7 +105,7 @@ void smpi_mpi_init()
 
                // make sure root is done before own initialization
                SIMIX_mutex_lock(smpi_global->start_stop_mutex);
 
                // make sure root is done before own initialization
                SIMIX_mutex_lock(smpi_global->start_stop_mutex);
-               if (!smpi_global->root_ready) {
+               while (!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);
                        SIMIX_cond_wait(smpi_global->start_stop_cond, smpi_global->start_stop_mutex);
                }
                SIMIX_mutex_unlock(smpi_global->start_stop_mutex);
index 6bb7a8d..f879b9a 100644 (file)
@@ -1,6 +1,8 @@
 #include "private.h"
 #include <string.h>
 
 #include "private.h"
 #include <string.h>
 
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_bench, smpi, "Logging specific to SMPI (benchmarking)");
+
 void smpi_execute(double duration) {
         smx_host_t host = SIMIX_host_self();
         smx_action_t action;
 void smpi_execute(double duration) {
         smx_host_t host = SIMIX_host_self();
         smx_action_t action;
@@ -56,10 +58,10 @@ void smpi_do_once_1(const char *file, int line) {
        }
        if (NULL == curr) {
                curr = xbt_new(s_smpi_do_once_duration_node_t, 1);
        }
        if (NULL == curr) {
                curr = xbt_new(s_smpi_do_once_duration_node_t, 1);
-               curr->file = xbt_strdup(file);
-               curr->line = line;
+               curr->file     = xbt_strdup(file);
+               curr->line     = line;
                curr->duration = -1;
                curr->duration = -1;
-               curr->next = NULL;
+               curr->next     = NULL;
                if (NULL == prev) {
                        smpi_global->do_once_duration_nodes = curr;
                } else {
                if (NULL == prev) {
                        smpi_global->do_once_duration_nodes = curr;
                } else {
@@ -71,14 +73,14 @@ void smpi_do_once_1(const char *file, int line) {
 
 int smpi_do_once_2() {
        double duration = *(smpi_global->do_once_duration);
 
 int smpi_do_once_2() {
        double duration = *(smpi_global->do_once_duration);
-       if (0 < duration) {
-               SIMIX_mutex_unlock(smpi_global->do_once_mutex);
-               smpi_execute(duration);
-               smpi_bench_begin();
-               return 0;
+       if (0 > duration) {
+               smpi_start_timer();
+               return 1;
        }
        }
-       smpi_start_timer();
-       return 1;
+       SIMIX_mutex_unlock(smpi_global->do_once_mutex);
+       smpi_execute(duration);
+       smpi_bench_begin();
+       return 0;
 }
 
 void smpi_do_once_3() {
 }
 
 void smpi_do_once_3() {
index 4f8fed0..d285a00 100644 (file)
@@ -2,7 +2,9 @@
 
 #include "private.h"
 
 
 #include "private.h"
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi, XBT_LOG_ROOT_CAT, "All SMPI categories");
+XBT_LOG_NEW_CATEGORY(smpi, "All SMPI categories");
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_kernel, smpi, "Logging specific to SMPI (kernel)");
 
 smpi_global_t     smpi_global     = NULL;
 
 
 smpi_global_t     smpi_global     = NULL;
 
index 1d4e1ca..ed45302 100644 (file)
@@ -1,13 +1,15 @@
 #include "private.h"
 
 #include "private.h"
 
-int MPI_Init(int *argc, char ***argv)
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_mpi, smpi, "Logging specific to SMPI (mpi)");
+
+int SMPI_MPI_Init(int *argc, char ***argv)
 {
        smpi_mpi_init();
        smpi_bench_begin();
        return MPI_SUCCESS;
 }
 
 {
        smpi_mpi_init();
        smpi_bench_begin();
        return MPI_SUCCESS;
 }
 
-int MPI_Finalize()
+int SMPI_MPI_Finalize()
 {
        smpi_bench_end();
        smpi_mpi_finalize();
 {
        smpi_bench_end();
        smpi_mpi_finalize();
@@ -16,13 +18,13 @@ int MPI_Finalize()
 
 // right now this just exits the current node, should send abort signal to all
 // hosts in the communicator;
 
 // right now this just exits the current node, should send abort signal to all
 // hosts in the communicator;
-int MPI_Abort(MPI_Comm comm, int errorcode)
+int SMPI_MPI_Abort(MPI_Comm comm, int errorcode)
 {
        smpi_exit(errorcode);
        return 0;
 }
 
 {
        smpi_exit(errorcode);
        return 0;
 }
 
-int MPI_Comm_size(MPI_Comm comm, int *size)
+int SMPI_MPI_Comm_size(MPI_Comm comm, int *size)
 {
        int retval = MPI_SUCCESS;
 
 {
        int retval = MPI_SUCCESS;
 
@@ -41,7 +43,7 @@ int MPI_Comm_size(MPI_Comm comm, int *size)
        return retval;
 }
 
        return retval;
 }
 
-int MPI_Comm_rank(MPI_Comm comm, int *rank)
+int SMPI_MPI_Comm_rank(MPI_Comm comm, int *rank)
 {
        int retval = MPI_SUCCESS;
 
 {
        int retval = MPI_SUCCESS;
 
@@ -60,7 +62,7 @@ int MPI_Comm_rank(MPI_Comm comm, int *rank)
        return retval;
 }
 
        return retval;
 }
 
-int MPI_Type_size(MPI_Datatype datatype, size_t *size)
+int SMPI_MPI_Type_size(MPI_Datatype datatype, size_t *size)
 {
        int retval = MPI_SUCCESS;
 
 {
        int retval = MPI_SUCCESS;
 
@@ -79,7 +81,7 @@ int MPI_Type_size(MPI_Datatype datatype, size_t *size)
        return retval;
 }
 
        return retval;
 }
 
-int MPI_Barrier(MPI_Comm comm)
+int SMPI_MPI_Barrier(MPI_Comm comm)
 {
        int retval = MPI_SUCCESS;
 
 {
        int retval = MPI_SUCCESS;
 
@@ -96,7 +98,7 @@ int MPI_Barrier(MPI_Comm comm)
        return retval;
 }
 
        return retval;
 }
 
-int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request *request)
+int SMPI_MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request *request)
 {
        int retval = MPI_SUCCESS;
 
 {
        int retval = MPI_SUCCESS;
 
@@ -112,7 +114,7 @@ int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI
        return retval;
 }
 
        return retval;
 }
 
-int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status)
+int SMPI_MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status)
 {
        int retval = MPI_SUCCESS;
        smpi_mpi_request_t request;
 {
        int retval = MPI_SUCCESS;
        smpi_mpi_request_t request;
@@ -133,7 +135,7 @@ int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_
        return retval;
 }
 
        return retval;
 }
 
-int MPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request *request)
+int SMPI_MPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request *request)
 {
        int retval = MPI_SUCCESS;
 
 {
        int retval = MPI_SUCCESS;
 
@@ -149,7 +151,7 @@ int MPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI
        return retval;
 }
 
        return retval;
 }
 
-int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
+int SMPI_MPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
 {
        int retval = MPI_SUCCESS;
        smpi_mpi_request_t request;
 {
        int retval = MPI_SUCCESS;
        smpi_mpi_request_t request;
@@ -170,7 +172,7 @@ int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_
        return retval;
 }
 
        return retval;
 }
 
-int MPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm) {
+int SMPI_MPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm) {
 
        int retval = MPI_SUCCESS;
        int rank;
 
        int retval = MPI_SUCCESS;
        int rank;
@@ -199,7 +201,7 @@ int MPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm co
 
 // FIXME: needs to return null in event of MPI_UNDEFINED color...
 // FIXME: seriously, this isn't pretty
 
 // FIXME: needs to return null in event of MPI_UNDEFINED color...
 // FIXME: seriously, this isn't pretty
-int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *comm_out)
+int SMPI_MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *comm_out)
 {
        int retval = MPI_SUCCESS;
 
 {
        int retval = MPI_SUCCESS;
 
index 0097875..e22363f 100644 (file)
@@ -1,5 +1,7 @@
 #include "private.h"
 
 #include "private.h"
 
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_receiver, smpi, "Logging specific to SMPI (receiver)");
+
 int smpi_receiver(int argc, char **argv)
 {
        smx_process_t self;
 int smpi_receiver(int argc, char **argv)
 {
        smx_process_t self;
index c1c8050..1df105f 100644 (file)
@@ -1,9 +1,12 @@
 #include "private.h"
 
 #include "private.h"
 
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_sender, smpi, "Logging specific to SMPI (sender)");
+
 int smpi_sender(int argc, char **argv)
 {
        smx_process_t self;
        smx_host_t shost;
 int smpi_sender(int argc, char **argv)
 {
        smx_process_t self;
        smx_host_t shost;
+
        int index;
 
        xbt_fifo_t request_queue;
        int index;
 
        xbt_fifo_t request_queue;
@@ -77,10 +80,6 @@ int smpi_sender(int argc, char **argv)
                        message->forward = (request->forward - 1) / 2;
                        request->forward = request->forward / 2;
 
                        message->forward = (request->forward - 1) / 2;
                        request->forward = request->forward / 2;
 
-                       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]);
-
                        if (0 < request->forward) {
                                request->dst = (request->dst + message->forward + 1) % request->comm->size;
                                SIMIX_mutex_lock(request_queue_mutex);
                        if (0 < request->forward) {
                                request->dst = (request->dst + message->forward + 1) % request->comm->size;
                                SIMIX_mutex_lock(request_queue_mutex);
@@ -94,11 +93,16 @@ int smpi_sender(int argc, char **argv)
 
                        SIMIX_register_action_to_condition(action, request->cond);
                        SIMIX_cond_wait(request->cond, request->mutex);
 
                        SIMIX_register_action_to_condition(action, request->cond);
                        SIMIX_cond_wait(request->cond, request->mutex);
+
                        SIMIX_unregister_action_to_condition(action, request->cond);
                        SIMIX_action_destroy(action);
 
                        SIMIX_mutex_unlock(request->mutex);
 
                        SIMIX_unregister_action_to_condition(action, request->cond);
                        SIMIX_action_destroy(action);
 
                        SIMIX_mutex_unlock(request->mutex);
 
+                       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]);
+
                        // wake up receiver if necessary
                        receiver_process = smpi_global->receiver_processes[dindex];
                        if (SIMIX_process_is_suspended(receiver_process)) {
                        // wake up receiver if necessary
                        receiver_process = smpi_global->receiver_processes[dindex];
                        if (SIMIX_process_is_suspended(receiver_process)) {
index ac5d372..71946a8 100644 (file)
@@ -1,10 +1,13 @@
 #include "private.h"
 
 #include "private.h"
 
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_util, smpi, "Logging specific to SMPI (utilities)");
+
 int smpi_gettimeofday(struct timeval *tv, struct timezone *tz)
 {
        double now;
 int smpi_gettimeofday(struct timeval *tv, struct timezone *tz)
 {
        double now;
-       int retval = 0;
+       int retval;
        smpi_bench_end();
        smpi_bench_end();
+       retval = 0;
        if (NULL == tv) {
                retval = -1;
        } else {
        if (NULL == tv) {
                retval = -1;
        } else {
@@ -44,9 +47,7 @@ unsigned int smpi_sleep(unsigned int seconds)
 void smpi_exit(int status)
 {
        smpi_bench_end();
 void smpi_exit(int status)
 {
        smpi_bench_end();
-       SIMIX_mutex_lock(smpi_global->running_hosts_count_mutex);
-       smpi_global->running_hosts_count--;
-       SIMIX_mutex_unlock(smpi_global->running_hosts_count_mutex);
+       smpi_mpi_finalize();
        SIMIX_process_kill(SIMIX_process_self());
        return;
 }
        SIMIX_process_kill(SIMIX_process_self());
        return;
 }