3 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_base, smpi,
4 "Logging specific to SMPI (base)");
5 XBT_LOG_EXTERNAL_CATEGORY(smpi_base);
6 XBT_LOG_EXTERNAL_CATEGORY(smpi_bench);
7 XBT_LOG_EXTERNAL_CATEGORY(smpi_kernel);
8 XBT_LOG_EXTERNAL_CATEGORY(smpi_mpi);
9 XBT_LOG_EXTERNAL_CATEGORY(smpi_receiver);
10 XBT_LOG_EXTERNAL_CATEGORY(smpi_sender);
11 XBT_LOG_EXTERNAL_CATEGORY(smpi_util);
13 smpi_mpi_global_t smpi_mpi_global = NULL;
15 void smpi_mpi_land_func(void *a, void *b, int *length,
16 MPI_Datatype * datatype);
18 void smpi_mpi_land_func(void *a, void *b, int *length,
19 MPI_Datatype * datatype)
22 if (*datatype == smpi_mpi_global->mpi_int) {
24 for (i = 0; i < *length; i++) {
30 void smpi_mpi_sum_func(void *a, void *b, int *length,
31 MPI_Datatype * datatype);
33 void smpi_mpi_sum_func(void *a, void *b, int *length, MPI_Datatype * datatype)
36 if (*datatype == smpi_mpi_global->mpi_int) {
38 for (i = 0; i < *length; i++) {
44 int smpi_mpi_comm_rank(smpi_mpi_communicator_t comm)
46 return comm->index_to_rank_map[smpi_host_index()];
49 void smpi_process_init()
53 smpi_host_data_t hdata;
55 smpi_global->running_hosts_count++;
57 // initialize some local variables
58 host = SIMIX_host_self();
60 hdata = xbt_new(s_smpi_host_data_t, 1);
62 for (i = 0; i < smpi_global->host_count && host != smpi_global->hosts[i]; i++);
65 hdata->mutex = SIMIX_mutex_init();
66 hdata->cond = SIMIX_cond_init();
68 SIMIX_host_set_data(host, hdata);
73 void smpi_process_finalize()
77 i = --smpi_global->running_hosts_count;
79 SIMIX_mutex_destroy(smpi_host_mutex());
80 SIMIX_cond_destroy(smpi_host_cond());
84 // wake up senders/receivers
85 for (i = 0; i < smpi_global->host_count; i++) {
86 if (SIMIX_process_is_suspended(smpi_global->sender_processes[i])) {
87 SIMIX_process_resume(smpi_global->sender_processes[i]);
89 if (SIMIX_process_is_suspended(smpi_global->receiver_processes[i])) {
90 SIMIX_process_resume(smpi_global->receiver_processes[i]);
94 SIMIX_mutex_destroy(smpi_mpi_global->mpi_comm_world->barrier_mutex);
95 SIMIX_cond_destroy(smpi_mpi_global->mpi_comm_world->barrier_cond);
96 xbt_free(smpi_mpi_global->mpi_comm_world);
98 xbt_free(smpi_mpi_global->mpi_byte);
99 xbt_free(smpi_mpi_global->mpi_int);
100 xbt_free(smpi_mpi_global->mpi_double);
102 xbt_free(smpi_mpi_global->mpi_land);
103 xbt_free(smpi_mpi_global->mpi_sum);
105 xbt_free(smpi_mpi_global);
111 int smpi_mpi_barrier(smpi_mpi_communicator_t comm)
114 SIMIX_mutex_lock(comm->barrier_mutex);
115 ++comm->barrier_count;
116 if (comm->barrier_count > comm->size) { // only happens on second barrier...
117 comm->barrier_count = 0;
118 } else if (comm->barrier_count == comm->size) {
119 SIMIX_cond_broadcast(comm->barrier_cond);
121 while (comm->barrier_count < comm->size) {
122 SIMIX_cond_wait(comm->barrier_cond, comm->barrier_mutex);
124 SIMIX_mutex_unlock(comm->barrier_mutex);
129 int smpi_mpi_isend(smpi_mpi_request_t request)
131 int retval = MPI_SUCCESS;
132 int index = smpi_host_index();
134 if (NULL == request) {
135 retval = MPI_ERR_INTERN;
137 xbt_fifo_push(smpi_global->pending_send_request_queues[index], request);
139 if (SIMIX_process_is_suspended(smpi_global->sender_processes[index])) {
140 SIMIX_process_resume(smpi_global->sender_processes[index]);
147 int smpi_mpi_irecv(smpi_mpi_request_t request)
149 int retval = MPI_SUCCESS;
150 int index = smpi_host_index();
152 if (NULL == request) {
153 retval = MPI_ERR_INTERN;
155 xbt_fifo_push(smpi_global->pending_recv_request_queues[index], request);
157 if (SIMIX_process_is_suspended(smpi_global->receiver_processes[index])) {
158 SIMIX_process_resume(smpi_global->receiver_processes[index]);
165 int smpi_mpi_wait(smpi_mpi_request_t request, smpi_mpi_status_t * status)
167 int retval = MPI_SUCCESS;
169 if (NULL == request) {
170 retval = MPI_ERR_INTERN;
172 SIMIX_mutex_lock(request->mutex);
173 while (!request->completed) {
174 SIMIX_cond_wait(request->cond, request->mutex);
176 if (NULL != status) {
177 status->MPI_SOURCE = request->src;
178 status->MPI_TAG = request->tag;
179 status->MPI_ERROR = MPI_SUCCESS;
181 SIMIX_mutex_unlock(request->mutex);