} 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
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);
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()
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++;
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;
SIMIX_cond_destroy(cond);
//SIMIX_action_destroy(action);
- // FIXME: check for success/failure?
-
return;
}
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)
} 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();
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);
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) {
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);
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);
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;
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];
// 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);
xbt_fifo_t request_queue;
smx_mutex_t request_queue_mutex;
- int size;
int running_hosts_count;
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];
// 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);
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);
SIMIX_cond_destroy(cond);
//SIMIX_action_destroy(action);
- // FIXME: check for success/failure?
-
smpi_bench_begin();
return 0;
}