#ifndef SMPI_H
#define SMPI_H
+#include <stddef.h>
#include <sys/time.h>
+#include <xbt/misc.h>
#include <xbt/function_types.h>
+SG_BEGIN_DECL()
+
#define SMPI_RAND_SEED 5
#define MPI_ANY_SOURCE -1
#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);
-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())
+SG_END_DECL()
+
#endif
#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);
}
}
-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()];
}
// 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);
#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;
}
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->next = NULL;
+ curr->next = NULL;
if (NULL == prev) {
smpi_global->do_once_duration_nodes = curr;
} else {
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() {
#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;
#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;
}
-int MPI_Finalize()
+int SMPI_MPI_Finalize()
{
smpi_bench_end();
smpi_mpi_finalize();
// 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;
}
-int MPI_Comm_size(MPI_Comm comm, int *size)
+int SMPI_MPI_Comm_size(MPI_Comm comm, int *size)
{
int retval = MPI_SUCCESS;
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;
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;
return retval;
}
-int MPI_Barrier(MPI_Comm comm)
+int SMPI_MPI_Barrier(MPI_Comm comm)
{
int retval = 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 SMPI_MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request *request)
{
int retval = MPI_SUCCESS;
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;
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;
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;
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;
// 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;
#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;
#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 index;
xbt_fifo_t request_queue;
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);
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_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)) {
#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 retval = 0;
+ int retval;
smpi_bench_end();
+ retval = 0;
if (NULL == tv) {
retval = -1;
} else {
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;
}