| 1 | //======================= int_div.cvl ======================
|
|---|
| 2 | $system[civlc] void $assert(_Bool expr, ...);
|
|---|
| 3 | int $int_div(int numerator, int denominator)
|
|---|
| 4 | {
|
|---|
| 5 | $assert(denominator != 0, "Possible division by zero");
|
|---|
| 6 | if (numerator == 0)
|
|---|
| 7 | return 0;
|
|---|
| 8 | if (numerator >= 0)
|
|---|
| 9 | {
|
|---|
| 10 | if (denominator >= 0)
|
|---|
| 11 | return numerator / denominator;
|
|---|
| 12 | else
|
|---|
| 13 | return -(numerator / (-denominator));
|
|---|
| 14 | }
|
|---|
| 15 | else
|
|---|
| 16 | {
|
|---|
| 17 | if (denominator >= 0)
|
|---|
| 18 | return -((-numerator) / denominator);
|
|---|
| 19 | else
|
|---|
| 20 | return (-numerator) / (-denominator);
|
|---|
| 21 | }
|
|---|
| 22 | }
|
|---|
| 23 | //======================== civlc.cvh =======================
|
|---|
| 24 | typedef struct $proc $proc;
|
|---|
| 25 | typedef struct $scope $scope;
|
|---|
| 26 | /*@ depends_on \nothing;
|
|---|
| 27 | @ executes_when $true;
|
|---|
| 28 | @*/
|
|---|
| 29 | $system[civlc] void $assert(_Bool expr, ...);
|
|---|
| 30 | /*@ depends_on \nothing;
|
|---|
| 31 | @ executes_when $true;
|
|---|
| 32 | @ assigns \nothing;
|
|---|
| 33 | @ reads \nothing;
|
|---|
| 34 | @*/
|
|---|
| 35 | $system[civlc] void $assume(_Bool expr);
|
|---|
| 36 | /*@ depends_on \nothing;
|
|---|
| 37 | @ executes_when $true;
|
|---|
| 38 | @*/
|
|---|
| 39 | $system[civlc] void $assert(_Bool expr, ...);
|
|---|
| 40 | /*@ depends_on \nothing;
|
|---|
| 41 | @ executes_when $true;
|
|---|
| 42 | @ assigns \nothing;
|
|---|
| 43 | @ reads \nothing;
|
|---|
| 44 | @*/
|
|---|
| 45 | $system[civlc] void $assume(_Bool expr);
|
|---|
| 46 | //========================= stdio.h ========================
|
|---|
| 47 | $system[stdio] int printf(char* restrict format, ...);
|
|---|
| 48 | //======================== civlc.cvh =======================
|
|---|
| 49 | /*@ depends_on \nothing;
|
|---|
| 50 | @ executes_when $true;
|
|---|
| 51 | @*/
|
|---|
| 52 | $system[civlc] void $assert(_Bool expr, ...);
|
|---|
| 53 | /*@ depends_on \nothing;
|
|---|
| 54 | @ executes_when $true;
|
|---|
| 55 | @ assigns \nothing;
|
|---|
| 56 | @ reads \nothing;
|
|---|
| 57 | @*/
|
|---|
| 58 | $system[civlc] void $assume(_Bool expr);
|
|---|
| 59 | //======================= bundle.cvh =======================
|
|---|
| 60 | typedef struct $bundle $bundle;
|
|---|
| 61 | /*@ pure;
|
|---|
| 62 | @ depends_on \nothing;
|
|---|
| 63 | @ executes_when $true;
|
|---|
| 64 | @*/
|
|---|
| 65 | $system[bundle] $bundle $bundle_pack(void* ptr, int size);
|
|---|
| 66 | /*@ depends_on \write(ptr);
|
|---|
| 67 | @ executes_when $true;
|
|---|
| 68 | @ assigns ptr;
|
|---|
| 69 | @ reads \nothing;
|
|---|
| 70 | @*/
|
|---|
| 71 | $system[bundle] void $bundle_unpack($bundle bundle, void* ptr);
|
|---|
| 72 | //===================== concurrency.cvh ====================
|
|---|
| 73 | typedef struct $gbarrier* $gbarrier;
|
|---|
| 74 | typedef struct $barrier* $barrier;
|
|---|
| 75 | /*@ depends_on \nothing;
|
|---|
| 76 | @ executes_when $true;
|
|---|
| 77 | @*/
|
|---|
| 78 | $system[concurrency] $gbarrier $gbarrier_create($scope scope, int size);
|
|---|
| 79 | /*@ depends_on \nothing;
|
|---|
| 80 | @ executes_when $true;
|
|---|
| 81 | @*/
|
|---|
| 82 | $system[concurrency] void $gbarrier_destroy($gbarrier barrier);
|
|---|
| 83 | /*@ depends_on \nothing;
|
|---|
| 84 | @ executes_when $true;
|
|---|
| 85 | @*/
|
|---|
| 86 | $system[concurrency] $barrier $barrier_create($scope scope, $gbarrier gbarrier, int place);
|
|---|
| 87 | /*@ depends_on \nothing;
|
|---|
| 88 | @ executes_when $true;
|
|---|
| 89 | @*/
|
|---|
| 90 | $system[concurrency] void $barrier_destroy($barrier barrier);
|
|---|
| 91 | typedef struct $collect_record $collect_record;
|
|---|
| 92 | typedef struct $gcollect_checker* $gcollect_checker;
|
|---|
| 93 | typedef struct $collect_checker* $collect_checker;
|
|---|
| 94 | /*@ depends_on \nothing;
|
|---|
| 95 | @ executes_when $true;
|
|---|
| 96 | @*/
|
|---|
| 97 | $system[concurrency] $gcollect_checker $gcollect_checker_create($scope scope);
|
|---|
| 98 | /*@ depends_on \nothing;
|
|---|
| 99 | @ executes_when $true;
|
|---|
| 100 | @*/
|
|---|
| 101 | $system[concurrency] int $gcollect_checker_destroy($gcollect_checker checker);
|
|---|
| 102 | /*@ depends_on \nothing;
|
|---|
| 103 | @ executes_when $true;
|
|---|
| 104 | @*/
|
|---|
| 105 | $system[concurrency] $collect_checker $collect_checker_create($scope scope, $gcollect_checker gchecker);
|
|---|
| 106 | /*@ depends_on \nothing;
|
|---|
| 107 | @ executes_when $true;
|
|---|
| 108 | @*/
|
|---|
| 109 | $system[concurrency] void $collect_checker_destroy($collect_checker checker);
|
|---|
| 110 | //========================== mpi.h =========================
|
|---|
| 111 | typedef enum $anon_enum_0{
|
|---|
| 112 | MPI_CHAR,
|
|---|
| 113 | MPI_CHARACTER,
|
|---|
| 114 | MPI_SIGNED_CHAR,
|
|---|
| 115 | MPI_UNSIGNED_CHAR,
|
|---|
| 116 | MPI_BYTE,
|
|---|
| 117 | MPI_WCHAR,
|
|---|
| 118 | MPI_SHORT,
|
|---|
| 119 | MPI_UNSIGNED_SHORT,
|
|---|
| 120 | MPI_INT,
|
|---|
| 121 | MPI_INT16_T,
|
|---|
| 122 | MPI_INT32_T,
|
|---|
| 123 | MPI_INT64_T,
|
|---|
| 124 | MPI_INT8_T,
|
|---|
| 125 | MPI_INTEGER,
|
|---|
| 126 | MPI_INTEGER1,
|
|---|
| 127 | MPI_INTEGER16,
|
|---|
| 128 | MPI_INTEGER2,
|
|---|
| 129 | MPI_INTEGER4,
|
|---|
| 130 | MPI_INTEGER8,
|
|---|
| 131 | MPI_UNSIGNED,
|
|---|
| 132 | MPI_LONG,
|
|---|
| 133 | MPI_UNSIGNED_LONG,
|
|---|
| 134 | MPI_FLOAT,
|
|---|
| 135 | MPI_DOUBLE,
|
|---|
| 136 | MPI_LONG_DOUBLE,
|
|---|
| 137 | MPI_LONG_LONG_INT,
|
|---|
| 138 | MPI_UNSIGNED_LONG_LONG,
|
|---|
| 139 | MPI_LONG_LONG,
|
|---|
| 140 | MPI_PACKED,
|
|---|
| 141 | MPI_LB,
|
|---|
| 142 | MPI_UB,
|
|---|
| 143 | MPI_UINT16_T,
|
|---|
| 144 | MPI_UINT32_T,
|
|---|
| 145 | MPI_UINT64_T,
|
|---|
| 146 | MPI_UINT8_T,
|
|---|
| 147 | MPI_FLOAT_INT,
|
|---|
| 148 | MPI_DOUBLE_INT,
|
|---|
| 149 | MPI_LONG_INT,
|
|---|
| 150 | MPI_SHORT_INT,
|
|---|
| 151 | MPI_2INT,
|
|---|
| 152 | MPI_LONG_DOUBLE_INT,
|
|---|
| 153 | MPI_AINT,
|
|---|
| 154 | MPI_OFFSET,
|
|---|
| 155 | MPI_2DOUBLE_PRECISION,
|
|---|
| 156 | MPI_2INTEGER,
|
|---|
| 157 | MPI_2REAL,
|
|---|
| 158 | MPI_C_BOOL,
|
|---|
| 159 | MPI_C_COMPLEX,
|
|---|
| 160 | MPI_C_DOUBLE_COMPLEX,
|
|---|
| 161 | MPI_C_FLOAT_COMPLEX,
|
|---|
| 162 | MPI_C_LONG_DOUBLE_COMPLEX,
|
|---|
| 163 | MPI_COMPLEX,
|
|---|
| 164 | MPI_COMPLEX16,
|
|---|
| 165 | MPI_COMPLEX32,
|
|---|
| 166 | MPI_COMPLEX4,
|
|---|
| 167 | MPI_COMPLEX8,
|
|---|
| 168 | MPI_REAL,
|
|---|
| 169 | MPI_REAL16,
|
|---|
| 170 | MPI_REAL2,
|
|---|
| 171 | MPI_REAL4,
|
|---|
| 172 | MPI_REAL8
|
|---|
| 173 | } MPI_Datatype;
|
|---|
| 174 | typedef struct MPI_Comm MPI_Comm;
|
|---|
| 175 | typedef struct MPI_Status{
|
|---|
| 176 | int MPI_SOURCE;
|
|---|
| 177 | int MPI_TAG;
|
|---|
| 178 | int MPI_ERROR;
|
|---|
| 179 | int size;
|
|---|
| 180 | } MPI_Status;
|
|---|
| 181 | int MPI_Send(void*, int, MPI_Datatype, int, int, MPI_Comm);
|
|---|
| 182 | int MPI_Recv(void*, int, MPI_Datatype, int, int, MPI_Comm, MPI_Status*);
|
|---|
| 183 | int MPI_Get_count(MPI_Status*, MPI_Datatype, int*);
|
|---|
| 184 | int MPI_Comm_size(MPI_Comm, int*);
|
|---|
| 185 | int MPI_Comm_rank(MPI_Comm, int*);
|
|---|
| 186 | //======================== comm.cvh ========================
|
|---|
| 187 | typedef struct $message{
|
|---|
| 188 | int source;
|
|---|
| 189 | int dest;
|
|---|
| 190 | int tag;
|
|---|
| 191 | $bundle data;
|
|---|
| 192 | int size;
|
|---|
| 193 | } $message;
|
|---|
| 194 | typedef struct $queue $queue;
|
|---|
| 195 | typedef struct $gcomm* $gcomm;
|
|---|
| 196 | typedef struct $comm* $comm;
|
|---|
| 197 | /*@ pure;
|
|---|
| 198 | @ depends_on \nothing;
|
|---|
| 199 | @ executes_when $true;
|
|---|
| 200 | @*/
|
|---|
| 201 | $atomic_f $message $message_pack(int source, int dest, int tag, void* data, int size);
|
|---|
| 202 | /*@ pure;
|
|---|
| 203 | @ depends_on \nothing;
|
|---|
| 204 | @ executes_when $true;
|
|---|
| 205 | @*/
|
|---|
| 206 | $atomic_f int $message_source($message message);
|
|---|
| 207 | /*@ pure;
|
|---|
| 208 | @ depends_on \nothing;
|
|---|
| 209 | @ executes_when $true;
|
|---|
| 210 | @*/
|
|---|
| 211 | $atomic_f int $message_tag($message message);
|
|---|
| 212 | /*@ pure;
|
|---|
| 213 | @ depends_on \nothing;
|
|---|
| 214 | @ executes_when $true;
|
|---|
| 215 | @*/
|
|---|
| 216 | $atomic_f int $message_dest($message message);
|
|---|
| 217 | /*@ pure;
|
|---|
| 218 | @ depends_on \nothing;
|
|---|
| 219 | @ executes_when $true;
|
|---|
| 220 | @*/
|
|---|
| 221 | $atomic_f int $message_size($message message);
|
|---|
| 222 | /*@ depends_on \write(buf);
|
|---|
| 223 | @ executes_when $true;
|
|---|
| 224 | @ assigns buf;
|
|---|
| 225 | @*/
|
|---|
| 226 | $atomic_f void $message_unpack($message message, void* buf, int size);
|
|---|
| 227 | /*@ depends_on \nothing;
|
|---|
| 228 | @ executes_when $true;
|
|---|
| 229 | @*/
|
|---|
| 230 | $system[comm] $gcomm $gcomm_create($scope scope, int size);
|
|---|
| 231 | /*@ depends_on \nothing;
|
|---|
| 232 | @ executes_when $true;
|
|---|
| 233 | @*/
|
|---|
| 234 | $system[comm] int $gcomm_destroy($gcomm gcomm, void* junkMsgs);
|
|---|
| 235 | /*@ depends_on \nothing;
|
|---|
| 236 | @ executes_when $true;
|
|---|
| 237 | @*/
|
|---|
| 238 | $system[comm] $comm $comm_create($scope scope, $gcomm gcomm, int place);
|
|---|
| 239 | /*@ depends_on \nothing;
|
|---|
| 240 | @ executes_when $true;
|
|---|
| 241 | @*/
|
|---|
| 242 | $system[comm] void $comm_destroy($comm comm);
|
|---|
| 243 | /*@ pure;
|
|---|
| 244 | @ depends_on \nothing;
|
|---|
| 245 | @ executes_when $true;
|
|---|
| 246 | @*/
|
|---|
| 247 | $system[comm] int $comm_size($comm comm);
|
|---|
| 248 | /*@ pure;
|
|---|
| 249 | @ depends_on \nothing;
|
|---|
| 250 | @ executes_when $true;
|
|---|
| 251 | @*/
|
|---|
| 252 | $atomic_f int $comm_place($comm comm);
|
|---|
| 253 | /*@ depends_on \write(comm);
|
|---|
| 254 | @ executes_when $true;
|
|---|
| 255 | @*/
|
|---|
| 256 | $system[comm] void $comm_enqueue($comm comm, $message message);
|
|---|
| 257 | /*@ depends_on \write(comm);
|
|---|
| 258 | @*/
|
|---|
| 259 | $system[comm] $message $comm_dequeue($comm comm, int source, int tag);
|
|---|
| 260 | //====================== civl-mpi.cvh ======================
|
|---|
| 261 | typedef enum _mpi_sys_status_{
|
|---|
| 262 | __UNINIT,
|
|---|
| 263 | __INIT,
|
|---|
| 264 | __FINALIZED
|
|---|
| 265 | } $mpi_sys_status;
|
|---|
| 266 | typedef struct MPI_Comm MPI_Comm;
|
|---|
| 267 | typedef struct MPI_Status MPI_Status;
|
|---|
| 268 | typedef struct $mpi_gcomm $mpi_gcomm;
|
|---|
| 269 | /*@ pure;
|
|---|
| 270 | @ depends_on \nothing;
|
|---|
| 271 | @*/
|
|---|
| 272 | $atomic_f int sizeofDatatype(MPI_Datatype);
|
|---|
| 273 | /*@ depends_on \nothing;
|
|---|
| 274 | @ executes_when $true;
|
|---|
| 275 | @ assigns \nothing;
|
|---|
| 276 | @ reads \nothing;
|
|---|
| 277 | @*/
|
|---|
| 278 | $system[civl-mpi] void $mpi_set_status($mpi_sys_status newStatus);
|
|---|
| 279 | /*@ pure;
|
|---|
| 280 | @ depends_on \nothing;
|
|---|
| 281 | @ executes_when $true;
|
|---|
| 282 | @*/
|
|---|
| 283 | $system[civl-mpi] $mpi_sys_status $mpi_get_status(void);
|
|---|
| 284 | /*@ depends_on \nothing;
|
|---|
| 285 | @ assigns \nothing;
|
|---|
| 286 | @ reads \nothing;
|
|---|
| 287 | @*/
|
|---|
| 288 | $atomic_f $mpi_gcomm $mpi_gcomm_create($scope, int);
|
|---|
| 289 | /*@ depends_on \nothing;
|
|---|
| 290 | @ assigns gc;
|
|---|
| 291 | @ reads \nothing;
|
|---|
| 292 | @*/
|
|---|
| 293 | $atomic_f void $mpi_gcomm_destroy($mpi_gcomm gc);
|
|---|
| 294 | MPI_Comm $mpi_comm_create($scope, $mpi_gcomm, int);
|
|---|
| 295 | void $mpi_comm_destroy(MPI_Comm);
|
|---|
| 296 | int $mpi_init(void);
|
|---|
| 297 | int $mpi_finalize(void);
|
|---|
| 298 | int $mpi_send(void*, int, MPI_Datatype, int, int, MPI_Comm);
|
|---|
| 299 | int $mpi_recv(void*, int, MPI_Datatype, int, int, MPI_Comm, MPI_Status*);
|
|---|
| 300 | $system[civl-mpi] void $mpi_assertConsistentType(void* buf, MPI_Datatype datatype);
|
|---|
| 301 | //========================= mpi.cvl ========================
|
|---|
| 302 | struct MPI_Comm{
|
|---|
| 303 | $comm p2p;
|
|---|
| 304 | $comm col;
|
|---|
| 305 | $collect_checker collect_checker;
|
|---|
| 306 | $barrier barrier;
|
|---|
| 307 | int gcommIndex;
|
|---|
| 308 | };
|
|---|
| 309 | int MPI_Comm_size(MPI_Comm comm, int* size)
|
|---|
| 310 | {
|
|---|
| 311 | $mpi_sys_status curr_status;
|
|---|
| 312 | curr_status = $mpi_get_status();
|
|---|
| 313 | $assert(curr_status == __INIT, "MPI_Comm_size() cannot be invoked without MPI_Init() being called before.\n");
|
|---|
| 314 | *size = $comm_size(comm.p2p);
|
|---|
| 315 | return 0;
|
|---|
| 316 | }
|
|---|
| 317 | int MPI_Comm_rank(MPI_Comm comm, int* rank)
|
|---|
| 318 | {
|
|---|
| 319 | $mpi_sys_status curr_status;
|
|---|
| 320 | curr_status = $mpi_get_status();
|
|---|
| 321 | $assert(curr_status == __INIT, "MPI_Comm_rank() cannot be invoked without MPI_Init() being called before.\n");
|
|---|
| 322 | *rank = $comm_place(comm.p2p);
|
|---|
| 323 | return 0;
|
|---|
| 324 | }
|
|---|
| 325 | int MPI_Send(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
|
|---|
| 326 | {
|
|---|
| 327 | $mpi_sys_status curr_status;
|
|---|
| 328 | curr_status = $mpi_get_status();
|
|---|
| 329 | $assert(curr_status == __INIT, "MPI_Send() cannot be invoked without MPI_Init() being called before.\n");
|
|---|
| 330 | $mpi_assertConsistentType(buf, datatype);
|
|---|
| 331 | int $sef$0 = $mpi_send(buf, count, datatype, dest, tag, comm);
|
|---|
| 332 | return $sef$0;
|
|---|
| 333 | }
|
|---|
| 334 | int MPI_Recv(void* buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status* status)
|
|---|
| 335 | {
|
|---|
| 336 | $mpi_sys_status curr_status;
|
|---|
| 337 | curr_status = $mpi_get_status();
|
|---|
| 338 | $assert(curr_status == __INIT, "MPI_Recv() cannot be invoked without MPI_Init() being called before.\n");
|
|---|
| 339 | $mpi_assertConsistentType(buf, datatype);
|
|---|
| 340 | int $sef$1 = $mpi_recv(buf, count, datatype, source, tag, comm, status);
|
|---|
| 341 | return $sef$1;
|
|---|
| 342 | }
|
|---|
| 343 | int MPI_Get_count(MPI_Status* status, MPI_Datatype datatype, int* count)
|
|---|
| 344 | {
|
|---|
| 345 | $mpi_sys_status curr_status;
|
|---|
| 346 | curr_status = $mpi_get_status();
|
|---|
| 347 | $assert(curr_status == __INIT, "MPI_Get_count() cannot be invoked without MPI_Init() being called before.\n");
|
|---|
| 348 | int $sef$2 = sizeofDatatype(datatype);
|
|---|
| 349 | *count = $int_div((status)->size, $sef$2);
|
|---|
| 350 | return 0;
|
|---|
| 351 | }
|
|---|
| 352 | //======================== civlc.cvh =======================
|
|---|
| 353 | /*@ depends_on \nothing;
|
|---|
| 354 | @ executes_when $true;
|
|---|
| 355 | @*/
|
|---|
| 356 | $system[civlc] void $assert(_Bool expr, ...);
|
|---|
| 357 | /*@ depends_on \nothing;
|
|---|
| 358 | @ executes_when $true;
|
|---|
| 359 | @ assigns \nothing;
|
|---|
| 360 | @ reads \nothing;
|
|---|
| 361 | @*/
|
|---|
| 362 | $system[civlc] void $assume(_Bool expr);
|
|---|
| 363 | //======================= bundle.cvh =======================
|
|---|
| 364 | /*@ pure;
|
|---|
| 365 | @ depends_on \nothing;
|
|---|
| 366 | @ executes_when $true;
|
|---|
| 367 | @*/
|
|---|
| 368 | $system[bundle] $bundle $bundle_pack(void* ptr, int size);
|
|---|
| 369 | /*@ depends_on \write(ptr);
|
|---|
| 370 | @ executes_when $true;
|
|---|
| 371 | @ assigns ptr;
|
|---|
| 372 | @ reads \nothing;
|
|---|
| 373 | @*/
|
|---|
| 374 | $system[bundle] void $bundle_unpack($bundle bundle, void* ptr);
|
|---|
| 375 | //===================== concurrency.cvh ====================
|
|---|
| 376 | /*@ depends_on \nothing;
|
|---|
| 377 | @ executes_when $true;
|
|---|
| 378 | @*/
|
|---|
| 379 | $system[concurrency] $gbarrier $gbarrier_create($scope scope, int size);
|
|---|
| 380 | /*@ depends_on \nothing;
|
|---|
| 381 | @ executes_when $true;
|
|---|
| 382 | @*/
|
|---|
| 383 | $system[concurrency] void $gbarrier_destroy($gbarrier barrier);
|
|---|
| 384 | /*@ depends_on \nothing;
|
|---|
| 385 | @ executes_when $true;
|
|---|
| 386 | @*/
|
|---|
| 387 | $system[concurrency] $barrier $barrier_create($scope scope, $gbarrier gbarrier, int place);
|
|---|
| 388 | /*@ depends_on \nothing;
|
|---|
| 389 | @ executes_when $true;
|
|---|
| 390 | @*/
|
|---|
| 391 | $system[concurrency] void $barrier_destroy($barrier barrier);
|
|---|
| 392 | /*@ depends_on \nothing;
|
|---|
| 393 | @ executes_when $true;
|
|---|
| 394 | @*/
|
|---|
| 395 | $system[concurrency] $gcollect_checker $gcollect_checker_create($scope scope);
|
|---|
| 396 | /*@ depends_on \nothing;
|
|---|
| 397 | @ executes_when $true;
|
|---|
| 398 | @*/
|
|---|
| 399 | $system[concurrency] int $gcollect_checker_destroy($gcollect_checker checker);
|
|---|
| 400 | /*@ depends_on \nothing;
|
|---|
| 401 | @ executes_when $true;
|
|---|
| 402 | @*/
|
|---|
| 403 | $system[concurrency] $collect_checker $collect_checker_create($scope scope, $gcollect_checker gchecker);
|
|---|
| 404 | /*@ depends_on \nothing;
|
|---|
| 405 | @ executes_when $true;
|
|---|
| 406 | @*/
|
|---|
| 407 | $system[concurrency] void $collect_checker_destroy($collect_checker checker);
|
|---|
| 408 | //========================= seq.cvh ========================
|
|---|
| 409 | /*@ depends_on \nothing;
|
|---|
| 410 | @*/
|
|---|
| 411 | $system[seq] void $seq_init(void* array, int count, void* value);
|
|---|
| 412 | //===================== concurrency.cvl ====================
|
|---|
| 413 | struct $gbarrier{
|
|---|
| 414 | int nprocs;
|
|---|
| 415 | $proc proc_map[];
|
|---|
| 416 | _Bool in_barrier[];
|
|---|
| 417 | int num_in_barrier;
|
|---|
| 418 | };
|
|---|
| 419 | struct $barrier{
|
|---|
| 420 | int place;
|
|---|
| 421 | $gbarrier gbarrier;
|
|---|
| 422 | };
|
|---|
| 423 | struct $collect_record{
|
|---|
| 424 | $bundle entries;
|
|---|
| 425 | _Bool marks[];
|
|---|
| 426 | int numMarked;
|
|---|
| 427 | };
|
|---|
| 428 | struct $gcollect_checker{
|
|---|
| 429 | int length;
|
|---|
| 430 | $collect_record records[];
|
|---|
| 431 | };
|
|---|
| 432 | struct $collect_checker{
|
|---|
| 433 | $gcollect_checker checker;
|
|---|
| 434 | };
|
|---|
| 435 | //======================== civlc.cvh =======================
|
|---|
| 436 | /*@ depends_on \nothing;
|
|---|
| 437 | @ executes_when $true;
|
|---|
| 438 | @*/
|
|---|
| 439 | $system[civlc] void $assert(_Bool expr, ...);
|
|---|
| 440 | /*@ depends_on \nothing;
|
|---|
| 441 | @ executes_when $true;
|
|---|
| 442 | @ assigns \nothing;
|
|---|
| 443 | @ reads \nothing;
|
|---|
| 444 | @*/
|
|---|
| 445 | $system[civlc] void $assume(_Bool expr);
|
|---|
| 446 | //======================= bundle.cvh =======================
|
|---|
| 447 | /*@ pure;
|
|---|
| 448 | @ depends_on \nothing;
|
|---|
| 449 | @ executes_when $true;
|
|---|
| 450 | @*/
|
|---|
| 451 | $system[bundle] $bundle $bundle_pack(void* ptr, int size);
|
|---|
| 452 | /*@ depends_on \write(ptr);
|
|---|
| 453 | @ executes_when $true;
|
|---|
| 454 | @ assigns ptr;
|
|---|
| 455 | @ reads \nothing;
|
|---|
| 456 | @*/
|
|---|
| 457 | $system[bundle] void $bundle_unpack($bundle bundle, void* ptr);
|
|---|
| 458 | //===================== concurrency.cvh ====================
|
|---|
| 459 | /*@ depends_on \nothing;
|
|---|
| 460 | @ executes_when $true;
|
|---|
| 461 | @*/
|
|---|
| 462 | $system[concurrency] $gbarrier $gbarrier_create($scope scope, int size);
|
|---|
| 463 | /*@ depends_on \nothing;
|
|---|
| 464 | @ executes_when $true;
|
|---|
| 465 | @*/
|
|---|
| 466 | $system[concurrency] void $gbarrier_destroy($gbarrier barrier);
|
|---|
| 467 | /*@ depends_on \nothing;
|
|---|
| 468 | @ executes_when $true;
|
|---|
| 469 | @*/
|
|---|
| 470 | $system[concurrency] $barrier $barrier_create($scope scope, $gbarrier gbarrier, int place);
|
|---|
| 471 | /*@ depends_on \nothing;
|
|---|
| 472 | @ executes_when $true;
|
|---|
| 473 | @*/
|
|---|
| 474 | $system[concurrency] void $barrier_destroy($barrier barrier);
|
|---|
| 475 | /*@ depends_on \nothing;
|
|---|
| 476 | @ executes_when $true;
|
|---|
| 477 | @*/
|
|---|
| 478 | $system[concurrency] $gcollect_checker $gcollect_checker_create($scope scope);
|
|---|
| 479 | /*@ depends_on \nothing;
|
|---|
| 480 | @ executes_when $true;
|
|---|
| 481 | @*/
|
|---|
| 482 | $system[concurrency] int $gcollect_checker_destroy($gcollect_checker checker);
|
|---|
| 483 | /*@ depends_on \nothing;
|
|---|
| 484 | @ executes_when $true;
|
|---|
| 485 | @*/
|
|---|
| 486 | $system[concurrency] $collect_checker $collect_checker_create($scope scope, $gcollect_checker gchecker);
|
|---|
| 487 | /*@ depends_on \nothing;
|
|---|
| 488 | @ executes_when $true;
|
|---|
| 489 | @*/
|
|---|
| 490 | $system[concurrency] void $collect_checker_destroy($collect_checker checker);
|
|---|
| 491 | //======================== comm.cvh ========================
|
|---|
| 492 | /*@ pure;
|
|---|
| 493 | @ depends_on \nothing;
|
|---|
| 494 | @ executes_when $true;
|
|---|
| 495 | @*/
|
|---|
| 496 | $atomic_f $message $message_pack(int source, int dest, int tag, void* data, int size);
|
|---|
| 497 | /*@ pure;
|
|---|
| 498 | @ depends_on \nothing;
|
|---|
| 499 | @ executes_when $true;
|
|---|
| 500 | @*/
|
|---|
| 501 | $atomic_f int $message_source($message message);
|
|---|
| 502 | /*@ pure;
|
|---|
| 503 | @ depends_on \nothing;
|
|---|
| 504 | @ executes_when $true;
|
|---|
| 505 | @*/
|
|---|
| 506 | $atomic_f int $message_tag($message message);
|
|---|
| 507 | /*@ pure;
|
|---|
| 508 | @ depends_on \nothing;
|
|---|
| 509 | @ executes_when $true;
|
|---|
| 510 | @*/
|
|---|
| 511 | $atomic_f int $message_dest($message message);
|
|---|
| 512 | /*@ pure;
|
|---|
| 513 | @ depends_on \nothing;
|
|---|
| 514 | @ executes_when $true;
|
|---|
| 515 | @*/
|
|---|
| 516 | $atomic_f int $message_size($message message);
|
|---|
| 517 | /*@ depends_on \write(buf);
|
|---|
| 518 | @ executes_when $true;
|
|---|
| 519 | @ assigns buf;
|
|---|
| 520 | @*/
|
|---|
| 521 | $atomic_f void $message_unpack($message message, void* buf, int size);
|
|---|
| 522 | /*@ depends_on \nothing;
|
|---|
| 523 | @ executes_when $true;
|
|---|
| 524 | @*/
|
|---|
| 525 | $system[comm] $gcomm $gcomm_create($scope scope, int size);
|
|---|
| 526 | /*@ depends_on \nothing;
|
|---|
| 527 | @ executes_when $true;
|
|---|
| 528 | @*/
|
|---|
| 529 | $system[comm] int $gcomm_destroy($gcomm gcomm, void* junkMsgs);
|
|---|
| 530 | /*@ depends_on \nothing;
|
|---|
| 531 | @ executes_when $true;
|
|---|
| 532 | @*/
|
|---|
| 533 | $system[comm] $comm $comm_create($scope scope, $gcomm gcomm, int place);
|
|---|
| 534 | /*@ depends_on \nothing;
|
|---|
| 535 | @ executes_when $true;
|
|---|
| 536 | @*/
|
|---|
| 537 | $system[comm] void $comm_destroy($comm comm);
|
|---|
| 538 | /*@ pure;
|
|---|
| 539 | @ depends_on \nothing;
|
|---|
| 540 | @ executes_when $true;
|
|---|
| 541 | @*/
|
|---|
| 542 | $system[comm] int $comm_size($comm comm);
|
|---|
| 543 | /*@ pure;
|
|---|
| 544 | @ depends_on \nothing;
|
|---|
| 545 | @ executes_when $true;
|
|---|
| 546 | @*/
|
|---|
| 547 | $atomic_f int $comm_place($comm comm);
|
|---|
| 548 | /*@ depends_on \write(comm);
|
|---|
| 549 | @ executes_when $true;
|
|---|
| 550 | @*/
|
|---|
| 551 | $system[comm] void $comm_enqueue($comm comm, $message message);
|
|---|
| 552 | /*@ depends_on \write(comm);
|
|---|
| 553 | @*/
|
|---|
| 554 | $system[comm] $message $comm_dequeue($comm comm, int source, int tag);
|
|---|
| 555 | //========================== mpi.h =========================
|
|---|
| 556 | int MPI_Send(void*, int, MPI_Datatype, int, int, MPI_Comm);
|
|---|
| 557 | int MPI_Recv(void*, int, MPI_Datatype, int, int, MPI_Comm, MPI_Status*);
|
|---|
| 558 | int MPI_Get_count(MPI_Status*, MPI_Datatype, int*);
|
|---|
| 559 | int MPI_Comm_size(MPI_Comm, int*);
|
|---|
| 560 | int MPI_Comm_rank(MPI_Comm, int*);
|
|---|
| 561 | //====================== civl-mpi.cvh ======================
|
|---|
| 562 | /*@ pure;
|
|---|
| 563 | @ depends_on \nothing;
|
|---|
| 564 | @*/
|
|---|
| 565 | $atomic_f int sizeofDatatype(MPI_Datatype);
|
|---|
| 566 | /*@ depends_on \nothing;
|
|---|
| 567 | @ executes_when $true;
|
|---|
| 568 | @ assigns \nothing;
|
|---|
| 569 | @ reads \nothing;
|
|---|
| 570 | @*/
|
|---|
| 571 | $system[civl-mpi] void $mpi_set_status($mpi_sys_status newStatus);
|
|---|
| 572 | /*@ pure;
|
|---|
| 573 | @ depends_on \nothing;
|
|---|
| 574 | @ executes_when $true;
|
|---|
| 575 | @*/
|
|---|
| 576 | $system[civl-mpi] $mpi_sys_status $mpi_get_status(void);
|
|---|
| 577 | /*@ depends_on \nothing;
|
|---|
| 578 | @ assigns \nothing;
|
|---|
| 579 | @ reads \nothing;
|
|---|
| 580 | @*/
|
|---|
| 581 | $atomic_f $mpi_gcomm $mpi_gcomm_create($scope, int);
|
|---|
| 582 | /*@ depends_on \nothing;
|
|---|
| 583 | @ assigns gc;
|
|---|
| 584 | @ reads \nothing;
|
|---|
| 585 | @*/
|
|---|
| 586 | $atomic_f void $mpi_gcomm_destroy($mpi_gcomm gc);
|
|---|
| 587 | MPI_Comm $mpi_comm_create($scope, $mpi_gcomm, int);
|
|---|
| 588 | void $mpi_comm_destroy(MPI_Comm);
|
|---|
| 589 | int $mpi_init(void);
|
|---|
| 590 | int $mpi_finalize(void);
|
|---|
| 591 | int $mpi_send(void*, int, MPI_Datatype, int, int, MPI_Comm);
|
|---|
| 592 | int $mpi_recv(void*, int, MPI_Datatype, int, int, MPI_Comm, MPI_Status*);
|
|---|
| 593 | $system[civl-mpi] void $mpi_assertConsistentType(void* buf, MPI_Datatype datatype);
|
|---|
| 594 | //========================= seq.cvh ========================
|
|---|
| 595 | /*@ depends_on \nothing;
|
|---|
| 596 | @*/
|
|---|
| 597 | $system[seq] void $seq_init(void* array, int count, void* value);
|
|---|
| 598 | //====================== civl-mpi.cvl ======================
|
|---|
| 599 | char* getCoroutineName(int tag);
|
|---|
| 600 | struct $mpi_gcomm{
|
|---|
| 601 | $gcomm p2p;
|
|---|
| 602 | $gcomm col;
|
|---|
| 603 | $gcollect_checker collect_checker;
|
|---|
| 604 | $gbarrier gbarrier;
|
|---|
| 605 | };
|
|---|
| 606 | int sizeofDatatype(MPI_Datatype datatype)
|
|---|
| 607 | {
|
|---|
| 608 | switch (datatype)
|
|---|
| 609 | {
|
|---|
| 610 | case MPI_INT:
|
|---|
| 611 | return sizeof(int);
|
|---|
| 612 | case MPI_2INT:
|
|---|
| 613 | return sizeof(int) * 2;
|
|---|
| 614 | case MPI_FLOAT:
|
|---|
| 615 | return sizeof(float);
|
|---|
| 616 | case MPI_DOUBLE:
|
|---|
| 617 | return sizeof(double);
|
|---|
| 618 | case MPI_CHAR:
|
|---|
| 619 | return sizeof(char);
|
|---|
| 620 | case MPI_BYTE:
|
|---|
| 621 | return sizeof(char);
|
|---|
| 622 | case MPI_SHORT:
|
|---|
| 623 | return sizeof(short);
|
|---|
| 624 | case MPI_LONG:
|
|---|
| 625 | return sizeof(long);
|
|---|
| 626 | case MPI_LONG_DOUBLE:
|
|---|
| 627 | return sizeof(long double);
|
|---|
| 628 | case MPI_LONG_LONG_INT:
|
|---|
| 629 | return sizeof(long long);
|
|---|
| 630 | case MPI_LONG_LONG:
|
|---|
| 631 | return sizeof(long long);
|
|---|
| 632 | case MPI_UNSIGNED_LONG_LONG:
|
|---|
| 633 | return sizeof(unsigned long long);
|
|---|
| 634 | default:
|
|---|
| 635 | $assert(0, "Unreachable");
|
|---|
| 636 | }
|
|---|
| 637 | }
|
|---|
| 638 | $mpi_gcomm $mpi_gcomm_create($scope scope, int size)
|
|---|
| 639 | {
|
|---|
| 640 | $mpi_gcomm result;
|
|---|
| 641 | result.p2p = $gcomm_create(scope, size);
|
|---|
| 642 | result.col = $gcomm_create(scope, size);
|
|---|
| 643 | result.collect_checker = $gcollect_checker_create(scope);
|
|---|
| 644 | result.gbarrier = $gbarrier_create(scope, size);
|
|---|
| 645 | return result;
|
|---|
| 646 | }
|
|---|
| 647 | void $mpi_gcomm_destroy($mpi_gcomm gc)
|
|---|
| 648 | {
|
|---|
| 649 | int numJunkRecord;
|
|---|
| 650 | int numJunkMsg;
|
|---|
| 651 | $message junkMsgs[];
|
|---|
| 652 | $seq_init(&(junkMsgs), 0, (void*)0);
|
|---|
| 653 | numJunkMsg = $gcomm_destroy(gc.p2p, &(junkMsgs));
|
|---|
| 654 | {
|
|---|
| 655 | int i = 0;
|
|---|
| 656 | for (; i < numJunkMsg; i = i + 1)
|
|---|
| 657 | {
|
|---|
| 658 | int src;
|
|---|
| 659 | int dest;
|
|---|
| 660 | int tag;
|
|---|
| 661 | src = $message_source(junkMsgs[i]);
|
|---|
| 662 | dest = $message_dest(junkMsgs[i]);
|
|---|
| 663 | tag = $message_tag(junkMsgs[i]);
|
|---|
| 664 | $assert($false, "MPI message leak: There is a message from rank %d to rank %d with tag %d has been sent but is never received in point-to-point communication.", src, dest, tag);
|
|---|
| 665 | }
|
|---|
| 666 | }
|
|---|
| 667 | numJunkMsg = $gcomm_destroy(gc.col, &(junkMsgs));
|
|---|
| 668 | {
|
|---|
| 669 | int i = 0;
|
|---|
| 670 | for (; i < numJunkMsg; i = i + 1)
|
|---|
| 671 | {
|
|---|
| 672 | int src;
|
|---|
| 673 | int tag;
|
|---|
| 674 | char* routine;
|
|---|
| 675 | src = $message_source(junkMsgs[i]);
|
|---|
| 676 | tag = $message_tag(junkMsgs[i]);
|
|---|
| 677 | routine = getCoroutineName(tag);
|
|---|
| 678 | $assert($false, "MPI message leak: There is a message sent by rank %d for collective routine %s that is never received.", src, routine);
|
|---|
| 679 | }
|
|---|
| 680 | }
|
|---|
| 681 | numJunkRecord = $gcollect_checker_destroy(gc.collect_checker);
|
|---|
| 682 | $gbarrier_destroy(gc.gbarrier);
|
|---|
| 683 | $assert(numJunkRecord == 0, "MPI collective routines are called inappropriately because there are %d collective records still remaining the collective routine checker.", numJunkRecord);
|
|---|
| 684 | }
|
|---|
| 685 | MPI_Comm $mpi_comm_create($scope scope, $mpi_gcomm gc, int rank)
|
|---|
| 686 | {
|
|---|
| 687 | MPI_Comm result;
|
|---|
| 688 | result.p2p = $comm_create(scope, gc.p2p, rank);
|
|---|
| 689 | result.col = $comm_create(scope, gc.col, rank);
|
|---|
| 690 | result.collect_checker = $collect_checker_create(scope, gc.collect_checker);
|
|---|
| 691 | result.barrier = $barrier_create(scope, gc.gbarrier, rank);
|
|---|
| 692 | result.gcommIndex = 0;
|
|---|
| 693 | return result;
|
|---|
| 694 | }
|
|---|
| 695 | void $mpi_comm_destroy(MPI_Comm comm)
|
|---|
| 696 | {
|
|---|
| 697 | $mpi_sys_status curr_status;
|
|---|
| 698 | curr_status = $mpi_get_status();
|
|---|
| 699 | if (comm.gcommIndex == 0)
|
|---|
| 700 | $assert(curr_status == __FINALIZED, "Process terminates without calling MPI_Finalize() first.");
|
|---|
| 701 | $comm_destroy(comm.p2p);
|
|---|
| 702 | $comm_destroy(comm.col);
|
|---|
| 703 | $collect_checker_destroy(comm.collect_checker);
|
|---|
| 704 | $barrier_destroy(comm.barrier);
|
|---|
| 705 | }
|
|---|
| 706 | int $mpi_init(void)
|
|---|
| 707 | {
|
|---|
| 708 | $mpi_set_status(__INIT);
|
|---|
| 709 | return 0;
|
|---|
| 710 | }
|
|---|
| 711 | int $mpi_finalize(void)
|
|---|
| 712 | {
|
|---|
| 713 | $mpi_set_status(__FINALIZED);
|
|---|
| 714 | return 0;
|
|---|
| 715 | }
|
|---|
| 716 | int $mpi_send(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
|
|---|
| 717 | {
|
|---|
| 718 | if (dest >= 0)
|
|---|
| 719 | {
|
|---|
| 720 | int $sef$3 = sizeofDatatype(datatype);
|
|---|
| 721 | int size = count * $sef$3;
|
|---|
| 722 | int place = $comm_place(comm.p2p);
|
|---|
| 723 | $message out = $message_pack(place, dest, tag, buf, size);
|
|---|
| 724 | $comm_enqueue(comm.p2p, out);
|
|---|
| 725 | }
|
|---|
| 726 | return 0;
|
|---|
| 727 | }
|
|---|
| 728 | int $mpi_recv(void* buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status* status)
|
|---|
| 729 | {
|
|---|
| 730 | if ((source >= 0) || (source == (-1)))
|
|---|
| 731 | {
|
|---|
| 732 | $message in;
|
|---|
| 733 | int place = $comm_place(comm.p2p);
|
|---|
| 734 | in = $comm_dequeue(comm.p2p, source, tag);
|
|---|
| 735 | int $sef$4 = sizeofDatatype(datatype);
|
|---|
| 736 | int size = count * $sef$4;
|
|---|
| 737 | $message_unpack(in, buf, size);
|
|---|
| 738 | if (status != (void*)0)
|
|---|
| 739 | {
|
|---|
| 740 | (status)->size = $message_size(in);
|
|---|
| 741 | (status)->MPI_SOURCE = $message_source(in);
|
|---|
| 742 | (status)->MPI_TAG = $message_tag(in);
|
|---|
| 743 | (status)->MPI_ERROR = 0;
|
|---|
| 744 | }
|
|---|
| 745 | }
|
|---|
| 746 | return 0;
|
|---|
| 747 | }
|
|---|
| 748 | char* getCoroutineName(int tag)
|
|---|
| 749 | {
|
|---|
| 750 | switch (tag)
|
|---|
| 751 | {
|
|---|
| 752 | case 9999:
|
|---|
| 753 | return "MPI_Bcast";
|
|---|
| 754 | case 9998:
|
|---|
| 755 | return "MPI_Reduce";
|
|---|
| 756 | case 9997:
|
|---|
| 757 | return "MPI_Allreduce";
|
|---|
| 758 | case 9996:
|
|---|
| 759 | return "MPI_Gather";
|
|---|
| 760 | case 9995:
|
|---|
| 761 | return "MPI_Scatter";
|
|---|
| 762 | case 9994:
|
|---|
| 763 | return "MPI_Gatherv";
|
|---|
| 764 | case 9993:
|
|---|
| 765 | return "MPI_Scatterv";
|
|---|
| 766 | case 9992:
|
|---|
| 767 | return "MPI_Allgather";
|
|---|
| 768 | case 9991:
|
|---|
| 769 | return "MPI_Reduce_scatter";
|
|---|
| 770 | case 9990:
|
|---|
| 771 | return "MPI_Alltoall";
|
|---|
| 772 | case 9989:
|
|---|
| 773 | return "MPI_Alltoallv";
|
|---|
| 774 | case 9988:
|
|---|
| 775 | return "MPI_Alltoallw";
|
|---|
| 776 | case 9987:
|
|---|
| 777 | return "MPI_Barrier";
|
|---|
| 778 | case 9986:
|
|---|
| 779 | return "MPI_Commdup";
|
|---|
| 780 | case 9985:
|
|---|
| 781 | return "MPI_Commfree";
|
|---|
| 782 | default:
|
|---|
| 783 | $assert($false, "Internal Error: Unexpected MPI routine tag:%d.\n", tag);
|
|---|
| 784 | }
|
|---|
| 785 | }
|
|---|
| 786 | //======================== civlc.cvh =======================
|
|---|
| 787 | /*@ depends_on \nothing;
|
|---|
| 788 | @ executes_when $true;
|
|---|
| 789 | @*/
|
|---|
| 790 | $system[civlc] void $assert(_Bool expr, ...);
|
|---|
| 791 | /*@ depends_on \nothing;
|
|---|
| 792 | @ executes_when $true;
|
|---|
| 793 | @ assigns \nothing;
|
|---|
| 794 | @ reads \nothing;
|
|---|
| 795 | @*/
|
|---|
| 796 | $system[civlc] void $assume(_Bool expr);
|
|---|
| 797 | //======================= bundle.cvh =======================
|
|---|
| 798 | /*@ pure;
|
|---|
| 799 | @ depends_on \nothing;
|
|---|
| 800 | @ executes_when $true;
|
|---|
| 801 | @*/
|
|---|
| 802 | $system[bundle] $bundle $bundle_pack(void* ptr, int size);
|
|---|
| 803 | /*@ depends_on \write(ptr);
|
|---|
| 804 | @ executes_when $true;
|
|---|
| 805 | @ assigns ptr;
|
|---|
| 806 | @ reads \nothing;
|
|---|
| 807 | @*/
|
|---|
| 808 | $system[bundle] void $bundle_unpack($bundle bundle, void* ptr);
|
|---|
| 809 | //======================== comm.cvh ========================
|
|---|
| 810 | /*@ pure;
|
|---|
| 811 | @ depends_on \nothing;
|
|---|
| 812 | @ executes_when $true;
|
|---|
| 813 | @*/
|
|---|
| 814 | $atomic_f $message $message_pack(int source, int dest, int tag, void* data, int size);
|
|---|
| 815 | /*@ pure;
|
|---|
| 816 | @ depends_on \nothing;
|
|---|
| 817 | @ executes_when $true;
|
|---|
| 818 | @*/
|
|---|
| 819 | $atomic_f int $message_source($message message);
|
|---|
| 820 | /*@ pure;
|
|---|
| 821 | @ depends_on \nothing;
|
|---|
| 822 | @ executes_when $true;
|
|---|
| 823 | @*/
|
|---|
| 824 | $atomic_f int $message_tag($message message);
|
|---|
| 825 | /*@ pure;
|
|---|
| 826 | @ depends_on \nothing;
|
|---|
| 827 | @ executes_when $true;
|
|---|
| 828 | @*/
|
|---|
| 829 | $atomic_f int $message_dest($message message);
|
|---|
| 830 | /*@ pure;
|
|---|
| 831 | @ depends_on \nothing;
|
|---|
| 832 | @ executes_when $true;
|
|---|
| 833 | @*/
|
|---|
| 834 | $atomic_f int $message_size($message message);
|
|---|
| 835 | /*@ depends_on \write(buf);
|
|---|
| 836 | @ executes_when $true;
|
|---|
| 837 | @ assigns buf;
|
|---|
| 838 | @*/
|
|---|
| 839 | $atomic_f void $message_unpack($message message, void* buf, int size);
|
|---|
| 840 | /*@ depends_on \nothing;
|
|---|
| 841 | @ executes_when $true;
|
|---|
| 842 | @*/
|
|---|
| 843 | $system[comm] $gcomm $gcomm_create($scope scope, int size);
|
|---|
| 844 | /*@ depends_on \nothing;
|
|---|
| 845 | @ executes_when $true;
|
|---|
| 846 | @*/
|
|---|
| 847 | $system[comm] int $gcomm_destroy($gcomm gcomm, void* junkMsgs);
|
|---|
| 848 | /*@ depends_on \nothing;
|
|---|
| 849 | @ executes_when $true;
|
|---|
| 850 | @*/
|
|---|
| 851 | $system[comm] $comm $comm_create($scope scope, $gcomm gcomm, int place);
|
|---|
| 852 | /*@ depends_on \nothing;
|
|---|
| 853 | @ executes_when $true;
|
|---|
| 854 | @*/
|
|---|
| 855 | $system[comm] void $comm_destroy($comm comm);
|
|---|
| 856 | /*@ pure;
|
|---|
| 857 | @ depends_on \nothing;
|
|---|
| 858 | @ executes_when $true;
|
|---|
| 859 | @*/
|
|---|
| 860 | $system[comm] int $comm_size($comm comm);
|
|---|
| 861 | /*@ pure;
|
|---|
| 862 | @ depends_on \nothing;
|
|---|
| 863 | @ executes_when $true;
|
|---|
| 864 | @*/
|
|---|
| 865 | $atomic_f int $comm_place($comm comm);
|
|---|
| 866 | /*@ depends_on \write(comm);
|
|---|
| 867 | @ executes_when $true;
|
|---|
| 868 | @*/
|
|---|
| 869 | $system[comm] void $comm_enqueue($comm comm, $message message);
|
|---|
| 870 | /*@ depends_on \write(comm);
|
|---|
| 871 | @*/
|
|---|
| 872 | $system[comm] $message $comm_dequeue($comm comm, int source, int tag);
|
|---|
| 873 | //======================== comm.cvl ========================
|
|---|
| 874 | struct $queue{
|
|---|
| 875 | int length;
|
|---|
| 876 | $message messages[];
|
|---|
| 877 | };
|
|---|
| 878 | struct $gcomm{
|
|---|
| 879 | int nprocs;
|
|---|
| 880 | $proc procs[];
|
|---|
| 881 | _Bool isInit[];
|
|---|
| 882 | $queue buf[][];
|
|---|
| 883 | };
|
|---|
| 884 | struct $comm{
|
|---|
| 885 | int place;
|
|---|
| 886 | $gcomm gcomm;
|
|---|
| 887 | };
|
|---|
| 888 | $message $message_pack(int source, int dest, int tag, void* data, int size)
|
|---|
| 889 | {
|
|---|
| 890 | $message result;
|
|---|
| 891 | result.source = source;
|
|---|
| 892 | result.dest = dest;
|
|---|
| 893 | result.tag = tag;
|
|---|
| 894 | result.data = $bundle_pack(data, size);
|
|---|
| 895 | result.size = size;
|
|---|
| 896 | return result;
|
|---|
| 897 | }
|
|---|
| 898 | int $message_source($message message)
|
|---|
| 899 | {
|
|---|
| 900 | return message.source;
|
|---|
| 901 | }
|
|---|
| 902 | int $message_tag($message message)
|
|---|
| 903 | {
|
|---|
| 904 | return message.tag;
|
|---|
| 905 | }
|
|---|
| 906 | int $message_dest($message message)
|
|---|
| 907 | {
|
|---|
| 908 | return message.dest;
|
|---|
| 909 | }
|
|---|
| 910 | int $message_size($message message)
|
|---|
| 911 | {
|
|---|
| 912 | return message.size;
|
|---|
| 913 | }
|
|---|
| 914 | void $message_unpack($message message, void* buf, int size)
|
|---|
| 915 | {
|
|---|
| 916 | $bundle_unpack(message.data, buf);
|
|---|
| 917 | $assert(message.size <= size, "Message of size %d exceeds the specified size %d.", message.size, size);
|
|---|
| 918 | }
|
|---|
| 919 | /*@ pure;
|
|---|
| 920 | @ depends_on \nothing;
|
|---|
| 921 | @ executes_when $true;
|
|---|
| 922 | @*/
|
|---|
| 923 | $atomic_f int $comm_place($comm comm)
|
|---|
| 924 | {
|
|---|
| 925 | return (comm)->place;
|
|---|
| 926 | }
|
|---|
| 927 | //======================== civlc.cvh =======================
|
|---|
| 928 | /*@ depends_on \nothing;
|
|---|
| 929 | @ executes_when $true;
|
|---|
| 930 | @*/
|
|---|
| 931 | $system[civlc] void $assert(_Bool expr, ...);
|
|---|
| 932 | /*@ depends_on \nothing;
|
|---|
| 933 | @ executes_when $true;
|
|---|
| 934 | @ assigns \nothing;
|
|---|
| 935 | @ reads \nothing;
|
|---|
| 936 | @*/
|
|---|
| 937 | $system[civlc] void $assume(_Bool expr);
|
|---|
| 938 | /*@ depends_on \nothing;
|
|---|
| 939 | @ executes_when $true;
|
|---|
| 940 | @*/
|
|---|
| 941 | $system[civlc] void $assert(_Bool expr, ...);
|
|---|
| 942 | /*@ depends_on \nothing;
|
|---|
| 943 | @ executes_when $true;
|
|---|
| 944 | @ assigns \nothing;
|
|---|
| 945 | @ reads \nothing;
|
|---|
| 946 | @*/
|
|---|
| 947 | $system[civlc] void $assume(_Bool expr);
|
|---|
| 948 | //======================= bundle.cvh =======================
|
|---|
| 949 | /*@ pure;
|
|---|
| 950 | @ depends_on \nothing;
|
|---|
| 951 | @ executes_when $true;
|
|---|
| 952 | @*/
|
|---|
| 953 | $system[bundle] $bundle $bundle_pack(void* ptr, int size);
|
|---|
| 954 | /*@ depends_on \write(ptr);
|
|---|
| 955 | @ executes_when $true;
|
|---|
| 956 | @ assigns ptr;
|
|---|
| 957 | @ reads \nothing;
|
|---|
| 958 | @*/
|
|---|
| 959 | $system[bundle] void $bundle_unpack($bundle bundle, void* ptr);
|
|---|
| 960 | //========================= seq.cvh ========================
|
|---|
| 961 | /*@ depends_on \nothing;
|
|---|
| 962 | @*/
|
|---|
| 963 | $system[seq] void $seq_init(void* array, int count, void* value);
|
|---|
| 964 | //======================== civlc.cvh =======================
|
|---|
| 965 | /*@ depends_on \nothing;
|
|---|
| 966 | @ executes_when $true;
|
|---|
| 967 | @*/
|
|---|
| 968 | $system[civlc] void $assert(_Bool expr, ...);
|
|---|
| 969 | /*@ depends_on \nothing;
|
|---|
| 970 | @ executes_when $true;
|
|---|
| 971 | @ assigns \nothing;
|
|---|
| 972 | @ reads \nothing;
|
|---|
| 973 | @*/
|
|---|
| 974 | $system[civlc] void $assume(_Bool expr);
|
|---|
| 975 | //========================= stdio.h ========================
|
|---|
| 976 | $system[stdio] int printf(char* restrict format, ...);
|
|---|
| 977 | //========================== mpi.h =========================
|
|---|
| 978 | int MPI_Send(void*, int, MPI_Datatype, int, int, MPI_Comm);
|
|---|
| 979 | int MPI_Recv(void*, int, MPI_Datatype, int, int, MPI_Comm, MPI_Status*);
|
|---|
| 980 | int MPI_Get_count(MPI_Status*, MPI_Datatype, int*);
|
|---|
| 981 | int MPI_Comm_size(MPI_Comm, int*);
|
|---|
| 982 | int MPI_Comm_rank(MPI_Comm, int*);
|
|---|
| 983 | //======================= sum_array.c ======================
|
|---|
| 984 | $input int _gen_argc;
|
|---|
| 985 | $input char _gen_argv[10][];
|
|---|
| 986 | $input long NB = 20;
|
|---|
| 987 | $input long N;
|
|---|
| 988 | //===================== MPITransformer =====================
|
|---|
| 989 | $input int _mpi_nprocs;
|
|---|
| 990 | $input int _mpi_nprocs_lo = 1;
|
|---|
| 991 | //======================= sum_array.c ======================
|
|---|
| 992 | $input int _mpi_nprocs_hi = 8;
|
|---|
| 993 | //===================== MPITransformer =====================
|
|---|
| 994 | $assume((_mpi_nprocs_lo <= _mpi_nprocs) && (_mpi_nprocs <= _mpi_nprocs_hi));
|
|---|
| 995 | $mpi_gcomm _mpi_gcomm = $mpi_gcomm_create($here, _mpi_nprocs);
|
|---|
| 996 | $mpi_gcomm _mpi_gcomms[];
|
|---|
| 997 | $seq_init(&(_mpi_gcomms), 1, &(_mpi_gcomm));
|
|---|
| 998 | void _mpi_process(int _mpi_rank)
|
|---|
| 999 | {
|
|---|
| 1000 | $mpi_sys_status _mpi_status = __UNINIT;
|
|---|
| 1001 | $assert(_mpi_status == __UNINIT);
|
|---|
| 1002 | MPI_Comm MPI_COMM_WORLD = $mpi_comm_create($here, _mpi_gcomm, _mpi_rank);
|
|---|
| 1003 | $system[sum_array] void $assume(_Bool expression);
|
|---|
| 1004 | $assume((0 < _gen_argc) && (_gen_argc < 10));
|
|---|
| 1005 | $assume((0 < N) && (N <= NB));
|
|---|
| 1006 | double oracle;
|
|---|
| 1007 | void master(void);
|
|---|
| 1008 | void slave(void);
|
|---|
| 1009 | int _gen_main(int argc, char** argv)
|
|---|
| 1010 | {
|
|---|
| 1011 | int myrank;
|
|---|
| 1012 | $mpi_init();
|
|---|
| 1013 | MPI_Comm_rank(MPI_COMM_WORLD, &(myrank));
|
|---|
| 1014 | if (!myrank)
|
|---|
| 1015 | master();
|
|---|
| 1016 | else
|
|---|
| 1017 | slave();
|
|---|
| 1018 | $mpi_finalize();
|
|---|
| 1019 | return 0;
|
|---|
| 1020 | }
|
|---|
| 1021 | void master(void)
|
|---|
| 1022 | {
|
|---|
| 1023 | float array[N];
|
|---|
| 1024 | double mysum;
|
|---|
| 1025 | double tmpsum;
|
|---|
| 1026 | unsigned long long step;
|
|---|
| 1027 | unsigned long long i;
|
|---|
| 1028 | int size;
|
|---|
| 1029 | MPI_Status status;
|
|---|
| 1030 | for (i = 0; i < N; i = i + 1)
|
|---|
| 1031 | array[i] = i + 1;
|
|---|
| 1032 | oracle = 0.0;
|
|---|
| 1033 | for (i = 0; i < N; i = i + 1)
|
|---|
| 1034 | oracle = oracle + (array[i]);
|
|---|
| 1035 | MPI_Comm_size(MPI_COMM_WORLD, &(size));
|
|---|
| 1036 | if (size != 1)
|
|---|
| 1037 | step = $int_div(N, size - 1);
|
|---|
| 1038 | else
|
|---|
| 1039 | step = N;
|
|---|
| 1040 | for (i = 0; i < (size - 1); i = i + 1)
|
|---|
| 1041 | MPI_Send(array + (i * step), step, MPI_FLOAT, i + 1, 100, MPI_COMM_WORLD);
|
|---|
| 1042 | {
|
|---|
| 1043 | i = (size - 1) * step;
|
|---|
| 1044 | mysum = 0;
|
|---|
| 1045 | for (; i < N; i = i + 1)
|
|---|
| 1046 | mysum = mysum + (array[i]);
|
|---|
| 1047 | }
|
|---|
| 1048 | for (i = 1; i < size; )
|
|---|
| 1049 | {
|
|---|
| 1050 | MPI_Recv(&(tmpsum), 1, MPI_DOUBLE, -1, 101, MPI_COMM_WORLD, &(status));
|
|---|
| 1051 | mysum = mysum + tmpsum;
|
|---|
| 1052 | i = i + 1;
|
|---|
| 1053 | }
|
|---|
| 1054 | $assert(oracle == mysum, "The sum of %d array elements is %f but the expected one is %f.\n", N, mysum, oracle);
|
|---|
| 1055 | printf("%lf\n", mysum);
|
|---|
| 1056 | }
|
|---|
| 1057 | void slave(void)
|
|---|
| 1058 | {
|
|---|
| 1059 | float array[N];
|
|---|
| 1060 | double sum;
|
|---|
| 1061 | unsigned long long i;
|
|---|
| 1062 | int count;
|
|---|
| 1063 | MPI_Status status;
|
|---|
| 1064 | MPI_Recv(array, N, MPI_FLOAT, 0, 100, MPI_COMM_WORLD, &(status));
|
|---|
| 1065 | MPI_Get_count(&(status), MPI_FLOAT, &(count));
|
|---|
| 1066 | {
|
|---|
| 1067 | i = 0;
|
|---|
| 1068 | sum = 0;
|
|---|
| 1069 | for (; i < count; i = i + 1)
|
|---|
| 1070 | sum = sum + (array[i]);
|
|---|
| 1071 | }
|
|---|
| 1072 | MPI_Send(&(sum), 1, MPI_DOUBLE, 0, 101, MPI_COMM_WORLD);
|
|---|
| 1073 | }
|
|---|
| 1074 | {
|
|---|
| 1075 | char* _gen_argv_tmp[10];
|
|---|
| 1076 | {
|
|---|
| 1077 | int i = 0;
|
|---|
| 1078 | for (; i < 10; i = i + 1)
|
|---|
| 1079 | _gen_argv_tmp[i] = &(_gen_argv[i][0]);
|
|---|
| 1080 | }
|
|---|
| 1081 | _gen_main(_gen_argc, &(_gen_argv_tmp[0]));
|
|---|
| 1082 | }
|
|---|
| 1083 | $mpi_comm_destroy(MPI_COMM_WORLD);
|
|---|
| 1084 | }
|
|---|
| 1085 | int main()
|
|---|
| 1086 | {
|
|---|
| 1087 | $parfor (int i: 0 .. _mpi_nprocs - 1)
|
|---|
| 1088 | _mpi_process(i);
|
|---|
| 1089 | $mpi_gcomm_destroy(_mpi_gcomm);
|
|---|
| 1090 | }
|
|---|
| 1091 |
|
|---|