#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;
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;
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;
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
#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;
// 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);
}
-void smpi_barrier(smpi_mpi_communicator_t comm)
+int smpi_mpi_barrier(smpi_mpi_communicator_t comm)
{
SIMIX_mutex_lock(comm->barrier_mutex);
}
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;
}
#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);
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()
{
return request;
}
+void smpi_request_free(void *pointer);
+
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;
}
+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) {
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;
int MPI_Abort(MPI_Comm comm, int errorcode)
{
smpi_exit(errorcode);
-
return 0;
}
} 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();
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;
}
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;
}
{
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;
}
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;
}
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;