1 | /* |
---|
2 | * mcast-get-tree.c - receive an MP tree from mcast-put-tree. |
---|
3 | * |
---|
4 | */ |
---|
5 | |
---|
6 | #include <stdio.h> |
---|
7 | |
---|
8 | #include <sys/types.h> |
---|
9 | #include <fcntl.h> |
---|
10 | #include <stdio.h> |
---|
11 | #include <math.h> |
---|
12 | #include "pvm3.h" |
---|
13 | #include "MP.h" |
---|
14 | #include "MP_PvmTransp.h" |
---|
15 | |
---|
16 | EXTERN MP_TranspOps_t pvm_ops; |
---|
17 | |
---|
18 | |
---|
19 | FILE *fd; |
---|
20 | |
---|
21 | #include "node.c" |
---|
22 | |
---|
23 | int |
---|
24 | process_request(root, lfd) |
---|
25 | node_t *root; |
---|
26 | FILE *lfd; |
---|
27 | { |
---|
28 | int more; |
---|
29 | |
---|
30 | more = print_node(root, lfd); |
---|
31 | return more; |
---|
32 | } |
---|
33 | |
---|
34 | main(argc, argv) |
---|
35 | int argc; |
---|
36 | char *argv[]; |
---|
37 | { |
---|
38 | int mytid; /* my task id */ |
---|
39 | int stid = 0; /* slave task id */ |
---|
40 | int n, i, more = 0, tids[5], nproc, me; |
---|
41 | int spawn_flag = PvmTaskDefault; |
---|
42 | char filename[128], *ofile = NULL; |
---|
43 | MP_Env_pt env = NULL; |
---|
44 | MP_Link_pt link = NULL; |
---|
45 | node_t *root = NULL; |
---|
46 | |
---|
47 | pvm_setopt(PvmAutoErr, 0); /* tell PVM not to print error to stdout */ |
---|
48 | if ((mytid = pvm_mytid()) < 0) exit(1); |
---|
49 | |
---|
50 | pvm_recv(-1, 0); |
---|
51 | pvm_upkint(&nproc, 1, 1); |
---|
52 | pvm_upkint(tids, nproc, 1); |
---|
53 | for (i = 0; i < nproc; i++) |
---|
54 | if (mytid == tids[i]) { |
---|
55 | me = tids[i]; |
---|
56 | break; |
---|
57 | } |
---|
58 | |
---|
59 | ofile = IMP_GetCmdlineArg(argc, argv, "-outfile"); |
---|
60 | if (ofile == NULL) ofile = "/tmp/get-tree.out"; |
---|
61 | fd = fopen(ofile, "w"); |
---|
62 | |
---|
63 | env = MP_AllocateEnv(); |
---|
64 | MP_SetEnvOption(env, MP_BUFFER_SIZE_OPT, pvm_getopt(PvmFragSize)); |
---|
65 | if ((env = MP_InitializeEnv(env)) == NULL) { |
---|
66 | fprintf(stderr, "%s: MP_EnvInitialize() failed!\n", argv[0]); |
---|
67 | exit(1); |
---|
68 | } |
---|
69 | MP_AddEnvTranspDevice(env, MP_PvmTransportDev, &pvm_ops); |
---|
70 | |
---|
71 | if ((link = MP_OpenLink(env, argc, argv)) == NULL) { |
---|
72 | fprintf(stderr, "%s: MP_OpenLink() failed!\n", argv[0]); |
---|
73 | exit(1); |
---|
74 | } |
---|
75 | |
---|
76 | MP_SetLinkOption(link, MP_LINK_LOG_MASK_OPT, MP_LOG_INIT_EVENTS); |
---|
77 | MP_SetLinkOption(link, MP_LINK_LOG_MASK_OPT, MP_LOG_READ_EVENTS); |
---|
78 | MP_SetLinkOption(link, MP_LINK_LOG_MASK_OPT, MP_LOG_WRITE_EVENTS); |
---|
79 | |
---|
80 | |
---|
81 | printf("server's annotated tree(s):\n"); |
---|
82 | do { |
---|
83 | if (MP_TestEofMsg(link)) MP_SkipMsg(link); |
---|
84 | printf("\n\ntype\t\t #annots value\t#children\n"); |
---|
85 | /* STEP 1: get the request */ |
---|
86 | root = m_get_node(link); |
---|
87 | /* STEP 2: process the request */ |
---|
88 | more = process_request(root, fd); |
---|
89 | |
---|
90 | /* STEP 3: cleanup */ |
---|
91 | free_tree(root); /* free the annotated tree */ |
---|
92 | root = NULL; |
---|
93 | free_label_table(); /* free the label table */ |
---|
94 | } while (more); |
---|
95 | |
---|
96 | pvm_initsend(PvmDataDefault); |
---|
97 | pvm_pkint(&me, 1, 1); |
---|
98 | pvm_send(pvm_parent(), 5); /* make sure message type matches what |
---|
99 | receiver expects */ |
---|
100 | |
---|
101 | fflush(fd); fclose(fd); |
---|
102 | MP_CloseLink(link); |
---|
103 | MP_ReleaseEnv(env); |
---|
104 | printf("\nbcast-get-tree: Successful termination.\n"); |
---|
105 | pvm_exit(); |
---|
106 | exit(0); |
---|
107 | |
---|
108 | bail: |
---|
109 | if (stid > 0) |
---|
110 | pvm_kill(stid); |
---|
111 | pvm_exit(); |
---|
112 | exit(1); |
---|
113 | } |
---|
114 | |
---|
115 | |
---|