-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtoy.c
99 lines (75 loc) · 2.29 KB
/
toy.c
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <RuntimeInterface.h>
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
struct test {
int a;
double b;
unsigned int c;
void* d;
int e;
struct test* f;
};
int main(int argc, char** argv) {
MPI_Init(&argc, &argv);
#ifdef NOSTACK
struct test* mystruct = malloc(sizeof(struct test) * 5);
#else
struct test mystruct[5];
#endif
int type = 0;
size_t count = 0;
#ifdef NOSTACK
int* buffer = malloc(sizeof(int) * 50);
#else
int buffer[50];
#endif
typeart_status status = typeart_get_type(mystruct, &type, &count);
if (status == TYPEART_OK)
printf("type (id=%i), count=%lu\n", type, count);
else
printf("[Demo] Toy Error: %i\n", status);
status = typeart_get_type(&(mystruct[2].e), &type, &count);
if (status == TYPEART_OK)
printf("(sub) type (id=%i), count=%lu\n", type, count);
else
printf("[Demo] Toy Error: %i\n", status);
status = typeart_get_type(&(mystruct[2].e), &type, &count);
if (status == TYPEART_OK)
printf("type (id=%i), count=%lu\n", type, count);
else
printf("[Demo] Toy Error: %i\n", status);
status = typeart_get_type(&(mystruct[2].c), &type, &count);
if (status == TYPEART_OK)
printf("(sub) type (id=%i), count=%lu\n", type, count);
else
printf("[Demo] Toy Error: %i\n", status);
status = typeart_get_type(&(mystruct[2].c), &type, &count);
if (status == TYPEART_OK)
printf("type (id=%i), count=%lu\n", type, count);
else
printf("[Demo] Toy Error: %i\n", status);
const void* base_address;
size_t offset;
status = typeart_get_containing_type(&(mystruct[2].c), &type, &count, &base_address, &offset);
if (status == TYPEART_OK)
printf("containing_type (id=%i), count=%lu, %p, %lu\n", type, count, base_address, offset);
else
printf("[Demo] Toy Error: %i\n", status);
printf("buffer\n");
status = typeart_get_containing_type(&(buffer[20]), &type, &count, &base_address, &offset);
if (status == TYPEART_OK)
printf("containing_type (id=%i), count=%lu, %p, %lu\n", type, count, base_address, offset);
else
printf("[Demo] Toy Error: %i\n", status);
MPI_Sendrecv(mystruct, 1, MPI_INT, 0, 0, buffer + 20, 1, MPI_INT, 0, 0, MPI_COMM_SELF, MPI_STATUS_IGNORE);
MPI_Finalize();
#ifdef NOSTACK
free(mystruct);
#else
#endif
#ifdef NOSTACK
free(buffer);
#else
#endif
}