Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e1f5b9dacc1562fff61e761d8a296b65b4a74b2f
[simgrid.git] / src / smpi / private.h
1 #ifndef SMPI_PRIVATE_H
2 #define SMPI_PRIVATE_H
3
4 #include "xbt/mallocator.h"
5 #include "xbt/xbt_os_time.h"
6
7 #include "simix/simix.h"
8
9 #include "smpi/smpi.h"
10
11 #define SMPI_DEFAULT_SPEED 100
12 #define SMPI_REQUEST_MALLOCATOR_SIZE 100
13 #define SMPI_MESSAGE_MALLOCATOR_SIZE 100
14
15 // smpi mpi communicator
16 typedef struct smpi_mpi_communicator_t {
17   int size;
18   int barrier_count;
19   smx_mutex_t barrier_mutex;
20   smx_cond_t barrier_cond;
21
22   int *rank_to_index_map;
23   int *index_to_rank_map;
24
25 } s_smpi_mpi_communicator_t;
26
27 // smpi mpi datatype
28 typedef struct smpi_mpi_datatype_t {
29   size_t size;
30   ptrdiff_t lb;
31   ptrdiff_t ub;
32   uint16_t flags; /* flags: has it been committed, etc ...*/
33   uint16_t id;    /* data id, normally the index in the data array. */
34 } s_smpi_mpi_datatype_t;
35
36 // smpi mpi request
37 typedef struct smpi_mpi_request_t {
38   smpi_mpi_communicator_t comm;
39   int src;
40   int dst;
41   int tag;
42
43   void *buf;
44   int count;
45   smpi_mpi_datatype_t datatype;
46
47   short int completed:1;
48   short int consumed:1;         /* for waitany */
49
50   smx_mutex_t mutex;
51   smx_cond_t cond;
52
53   void *data;
54   int forward;
55
56 } s_smpi_mpi_request_t;
57
58 // smpi mpi op
59 typedef struct smpi_mpi_op_t {
60   void (*func) (void *a, void *b, int *length, MPI_Datatype * datatype);
61 } s_smpi_mpi_op_t;
62
63 // smpi received message
64 typedef struct smpi_received_message_t {
65   smpi_mpi_communicator_t comm;
66   int src;
67   int tag;
68
69   void *buf;
70
71   void *data;
72   int forward;
73
74 } s_smpi_received_message_t;
75 typedef struct smpi_received_message_t *smpi_received_message_t;
76
77 typedef struct smpi_do_once_duration_node_t {
78   char *file;
79   int line;
80   double duration;
81   struct smpi_do_once_duration_node_t *next;
82 } s_smpi_do_once_duration_node_t;
83 typedef struct smpi_do_once_duration_node_t *smpi_do_once_duration_node_t;
84
85 typedef struct smpi_global_t {
86
87   // config vars
88   double reference_speed;
89
90   // state vars
91   int process_count;
92   xbt_mallocator_t request_mallocator;
93   xbt_mallocator_t message_mallocator;
94
95   smx_process_t *main_processes;
96
97   xbt_os_timer_t timer;
98   smx_cond_t timer_cond;
99
100   // keeps track of previous times
101   smpi_do_once_duration_node_t do_once_duration_nodes;
102   smx_mutex_t do_once_mutex;
103   double *do_once_duration;
104
105 } s_smpi_global_t;
106 typedef struct smpi_global_t *smpi_global_t;
107 extern smpi_global_t smpi_global;
108
109 typedef struct smpi_host_data_t {
110   int index;
111   smx_mutex_t mutex;
112   smx_cond_t cond;
113
114   smx_process_t main;
115   smx_process_t sender;
116   smx_process_t receiver;
117
118   int finalize;                 /* so that main process stops its sender&receiver */
119
120   xbt_fifo_t pending_recv_request_queue;
121   xbt_fifo_t pending_send_request_queue;
122   xbt_fifo_t received_message_queue;
123 } s_smpi_process_data_t;
124 typedef struct smpi_host_data_t *smpi_process_data_t;
125
126 // function prototypes
127 void smpi_process_init(int *argc, char ***argv);
128 void smpi_process_finalize(void);
129 int smpi_mpi_comm_rank(smpi_mpi_communicator_t comm);
130 int smpi_mpi_type_get_extent(MPI_Datatype datatype, MPI_Aint *lb, MPI_Aint *extent);
131
132 int smpi_mpi_bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm);
133 int smpi_mpi_barrier(smpi_mpi_communicator_t comm);
134
135 int smpi_mpi_isend(smpi_mpi_request_t request);
136 int smpi_mpi_irecv(smpi_mpi_request_t request);
137 int smpi_mpi_reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm);
138 int smpi_mpi_sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, int dest, int sendtag, 
139                             void *recvbuf, int recvcount, MPI_Datatype recvtype, int source, int recvtag,
140                           MPI_Comm comm, MPI_Status *status);
141 int smpi_mpi_wait(smpi_mpi_request_t request, smpi_mpi_status_t * status);
142 int smpi_mpi_waitall(int count, smpi_mpi_request_t requests[], smpi_mpi_status_t status[]);
143 int smpi_mpi_waitany(int count, smpi_mpi_request_t requests[], int *index, smpi_mpi_status_t status[]);
144
145
146 // utilities
147 void smpi_execute(double duration);
148 void smpi_start_timer(void);
149 double smpi_stop_timer(void);
150 void smpi_bench_begin(void);
151 void smpi_bench_end(void);
152 void smpi_bench_skip(void);
153
154 void smpi_global_init(void);
155 void smpi_global_destroy(void);
156 int smpi_process_index(void);
157 smx_mutex_t smpi_process_mutex(void);
158 smx_cond_t smpi_process_cond(void);
159 int smpi_run_simulation(int *argc, char **argv);
160 int smpi_create_request(void *buf, int count, smpi_mpi_datatype_t datatype,
161                         int src, int dst, int tag,
162                         smpi_mpi_communicator_t comm,
163                         smpi_mpi_request_t * request);
164
165 int smpi_sender(int argc, char *argv[]);
166 int smpi_receiver(int argc, char *argv[]);
167
168 #endif