This source file includes following definitions.
- rand_int
- time_cb
- main
1
2
3
4
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <fcntl.h>
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <string.h>
11 #ifndef WIN32
12 #include <unistd.h>
13 #include <sys/time.h>
14 #endif
15 #include <errno.h>
16
17 #include "opal/runtime/opal.h"
18 #include "opal/mca/event/event.h"
19
20 #include "orte/runtime/orte_globals.h"
21
22 int called = 0;
23
24 #define NEVENT 2000
25
26 opal_event_t* ev[NEVENT];
27
28 static int rand_int(int n)
29 {
30 #ifdef WIN32
31 return (int)(rand() % n);
32 #else
33 return (int)(random() % n);
34 #endif
35 }
36
37 static void time_cb(int fd, short event, void *arg)
38 {
39 struct timeval tv;
40 opal_event_t *tmp = (opal_event_t*)arg;
41
42 called++;
43
44 if (0 == (called % 1000)) {
45 fprintf(stderr, "Fired event %d\n", called);
46 }
47
48 if (called < 10*NEVENT) {
49 tv.tv_sec = 0;
50 tv.tv_usec = rand_int(50000);
51 opal_event_evtimer_add(tmp, &tv);
52 }
53 }
54
55 int main(int argc, char **argv)
56 {
57 struct timeval tv;
58 int i;
59 #ifdef WIN32
60 WORD wVersionRequested;
61 WSADATA wsaData;
62 int err;
63
64 wVersionRequested = MAKEWORD(2, 2);
65
66 err = WSAStartup(wVersionRequested, &wsaData);
67 #endif
68
69
70 opal_init(&argc, &argv);
71
72 for (i = 0; i < NEVENT; i++) {
73
74 ev[i] = (opal_event_t*)malloc(sizeof(opal_event_t));
75 opal_event_evtimer_set(orte_event_base, ev[i], time_cb, ev[i]);
76 tv.tv_sec = 0;
77 tv.tv_usec = rand_int(50000);
78 opal_event_evtimer_add(ev[i], &tv);
79 }
80
81 while (orte_event_base_active) {
82 opal_event_loop(orte_event_base, OPAL_EVLOOP_ONCE);
83 }
84
85 opal_finalize();
86 return (called < NEVENT);
87 }
88