Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e01c62461cec6869c5bcaa6bcfcbb59bf149e0ec
[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 } s_smpi_mpi_datatype_t;
31
32 // smpi mpi request
33 typedef struct smpi_mpi_request_t {
34   smpi_mpi_communicator_t comm;
35   int src;
36   int dst;
37   int tag;
38
39   void *buf;
40   int count;
41   smpi_mpi_datatype_t datatype;
42
43   short int completed:1;
44   short int consumed:1;         /* for waitany */
45
46   smx_mutex_t mutex;
47   smx_cond_t cond;
48
49   void *data;
50   int forward;
51
52 } s_smpi_mpi_request_t;
53
54 // smpi mpi op
55 typedef struct smpi_mpi_op_t {
56   void (*func) (void *a, void *b, int *length, MPI_Datatype * datatype);
57 } s_smpi_mpi_op_t;
58
59 // smpi received message
60 typedef struct smpi_received_message_t {
61   smpi_mpi_communicator_t comm;
62   int src;
63   int tag;
64
65   void *buf;
66
67   void *data;
68   int forward;
69
70 } s_smpi_received_message_t;
71 typedef struct smpi_received_message_t *smpi_received_message_t;
72
73 typedef struct smpi_do_once_duration_node_t {
74   char *file;
75   int line;
76   double duration;
77   struct smpi_do_once_duration_node_t *next;
78 } s_smpi_do_once_duration_node_t;
79 typedef struct smpi_do_once_duration_node_t *smpi_do_once_duration_node_t;
80
81 typedef struct smpi_global_t {
82
83   // config vars
84   double reference_speed;
85
86   // state vars
87   int process_count;
88   xbt_mallocator_t request_mallocator;
89   xbt_mallocator_t message_mallocator;
90
91   smx_process_t *main_processes;
92
93   xbt_os_timer_t timer;
94   smx_cond_t timer_cond;
95
96   // keeps track of previous times
97   smpi_do_once_duration_node_t do_once_duration_nodes;
98   smx_mutex_t do_once_mutex;
99   double *do_once_duration;
100
101 } s_smpi_global_t;
102 typedef struct smpi_global_t *smpi_global_t;
103 extern smpi_global_t smpi_global;
104
105 typedef struct smpi_host_data_t {
106   int index;
107   smx_mutex_t mutex;
108   smx_cond_t cond;
109
110   smx_process_t main;
111   smx_process_t sender;
112   smx_process_t receiver;
113
114   int finalize;                 /* so that main process stops its sender&receiver */
115
116   xbt_fifo_t pending_recv_request_queue;
117   xbt_fifo_t pending_send_request_queue;
118   xbt_fifo_t received_message_queue;
119 } s_smpi_process_data_t;
120 typedef struct smpi_host_data_t *smpi_process_data_t;
121
122 // function prototypes
123 void smpi_process_init(int *argc, char ***argv);
124 void smpi_process_finalize(void);
125 int smpi_mpi_comm_rank(smpi_mpi_communicator_t comm);
126
127 int smpi_mpi_bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm);
128 int smpi_mpi_barrier(smpi_mpi_communicator_t comm);
129
130 int smpi_mpi_isend(smpi_mpi_request_t request);
131 int smpi_mpi_irecv(smpi_mpi_request_t request);
132 int smpi_mpi_reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm);
133 int smpi_mpi_sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, int dest, int sendtag, 
134                             void *recvbuf, int recvcount, MPI_Datatype recvtype, int source, int recvtag,
135                           MPI_Comm comm, MPI_Status *status);
136 int smpi_mpi_wait(smpi_mpi_request_t request, smpi_mpi_status_t * status);
137 int smpi_mpi_waitall(int count, smpi_mpi_request_t requests[], smpi_mpi_status_t status[]);
138 int smpi_mpi_waitany(int count, smpi_mpi_request_t requests[], int *index, smpi_mpi_status_t status[]);
139
140
141 // utilities
142 void smpi_execute(double duration);
143 void smpi_start_timer(void);
144 double smpi_stop_timer(void);
145 void smpi_bench_begin(void);
146 void smpi_bench_end(void);
147 void smpi_bench_skip(void);
148
149 void smpi_global_init(void);
150 void smpi_global_destroy(void);
151 int smpi_process_index(void);
152 smx_mutex_t smpi_process_mutex(void);
153 smx_cond_t smpi_process_cond(void);
154 int smpi_run_simulation(int *argc, char **argv);
155 int smpi_create_request(void *buf, int count, smpi_mpi_datatype_t datatype,
156                         int src, int dst, int tag,
157                         smpi_mpi_communicator_t comm,
158                         smpi_mpi_request_t * request);
159
160 int smpi_sender(int argc, char *argv[]);
161 int smpi_receiver(int argc, char *argv[]);
162
163 #endif