-
Notifications
You must be signed in to change notification settings - Fork 0
/
mimpi_common.h
74 lines (53 loc) · 2.78 KB
/
mimpi_common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* This file is for declarations of common interfaces used in both
* MIMPI library (mimpi.c) and mimpirun program (mimpirun.c).
* */
#ifndef MIMPI_COMMON_H
#define MIMPI_COMMON_H
#include <assert.h>
#include <stdbool.h>
#include <stdnoreturn.h>
/*
Assert that expression doesn't evaluate to -1 (as almost every system function does in case of error).
Use as a function, with a semicolon, like: ASSERT_SYS_OK(close(fd));
(This is implemented with a 'do { ... } while(0)' block so that it can be used between if () and else.)
*/
#define ASSERT_SYS_OK(expr) \
do { \
if ((expr) == -1) \
syserr( \
"system command failed: %s\n\tIn function %s() in %s line %d.\n\tErrno: ", \
#expr, __func__, __FILE__, __LINE__ \
); \
} while(0)
/* Assert that expression evaluates to zero (otherwise use result as error number, as in pthreads). */
#define ASSERT_ZERO(expr) \
do { \
int const _errno = (expr); \
if (_errno != 0) \
syserr( \
"Failed: %s\n\tIn function %s() in %s line %d.\n\tErrno: ", \
#expr, __func__, __FILE__, __LINE__ \
); \
} while(0)
/* Prints with information about system error (errno) and quits. */
_Noreturn extern void syserr(const char* fmt, ...);
/* Prints (like printf) and quits. */
_Noreturn extern void fatal(const char* fmt, ...);
#define TODO fatal("UNIMPLEMENTED function %s", __PRETTY_FUNCTION__);
/////////////////////////////////////////////
// Put your declarations here
typedef enum {
MIMPI_Father = 0,
MIMPI_Left = 1,
MIMPI_Right = 2
} MIMPI_Tree;
int determine_read(int read, int write);
int determine_write(int write, int read);
int determine_gread(MIMPI_Tree pos);
int determine_gwrite(MIMPI_Tree pos);
int group_num(int rank, MIMPI_Tree pos);
int min(int a, int b);
int max(int a, int b);
void print_open_descriptors(void);
#endif // MIMPI_COMMON_H