1 | /* |
---|
2 | * slave.c *ACTUALLY, this file is named master.c* |
---|
3 | * |
---|
4 | * Send an MP tree to a single master. |
---|
5 | * |
---|
6 | * 9 Dec 1991 Manchek |
---|
7 | * 14 Oct 1992 Geist - revision to pvm3 |
---|
8 | * 6 Mar 1994 Geist - synch tasks and add direct route |
---|
9 | */ |
---|
10 | |
---|
11 | #include <stdio.h> |
---|
12 | |
---|
13 | #include <sys/types.h> |
---|
14 | #include <fcntl.h> |
---|
15 | #include <stdio.h> |
---|
16 | #include <math.h> |
---|
17 | #include "pvm3.h" |
---|
18 | #include "MP.h" |
---|
19 | |
---|
20 | #define ENCODING PvmDataRaw |
---|
21 | #define SLAVENAME "slave" |
---|
22 | |
---|
23 | EXTERN MP_TranspOps_t pvm_ops; |
---|
24 | |
---|
25 | FILE *fd; |
---|
26 | |
---|
27 | #include "node.c" |
---|
28 | #include "mp_pvm.c" |
---|
29 | |
---|
30 | |
---|
31 | int |
---|
32 | process_request(root, lfd) |
---|
33 | node_t *root; |
---|
34 | FILE *lfd; |
---|
35 | { |
---|
36 | int more; |
---|
37 | |
---|
38 | more = print_node(root, lfd); |
---|
39 | return more; |
---|
40 | } |
---|
41 | |
---|
42 | main(argc, argv) |
---|
43 | int argc; |
---|
44 | char *argv[]; |
---|
45 | { |
---|
46 | int mytid; /* my task id */ |
---|
47 | int stid = 0; /* slave task id */ |
---|
48 | int n, i, more = 0; |
---|
49 | int spawn_flag = PvmTaskDefault; |
---|
50 | char filename[128], *rhost = NULL; |
---|
51 | MP_Env_pt env = NULL; |
---|
52 | MP_Link_pt link = NULL; |
---|
53 | node_t *root = NULL; |
---|
54 | |
---|
55 | pvm_setopt(PvmAutoErr, 0); /* tell PVM not to print error to stdout */ |
---|
56 | if ((mytid = pvm_mytid()) < 0) { |
---|
57 | exit(1); |
---|
58 | } |
---|
59 | |
---|
60 | rhost = IMP_GetCmdlineArg(argc, argv, "-remhost"); |
---|
61 | if (rhost != NULL) spawn_flag = PvmTaskHost; |
---|
62 | /* start up slave task */ |
---|
63 | if (pvm_spawn(SLAVENAME, argv, spawn_flag, rhost, 1, &stid) < 0 || stid < 0) { |
---|
64 | fputs("can't initiate slave\n", stderr); |
---|
65 | goto bail; |
---|
66 | } |
---|
67 | |
---|
68 | printf("name of data file: "); |
---|
69 | scanf("%s", filename); |
---|
70 | |
---|
71 | pvm_initsend(PvmDataDefault); |
---|
72 | pvm_pkstr(filename); |
---|
73 | pvm_send(stid, 5); |
---|
74 | |
---|
75 | env = MP_AllocateEnv(); |
---|
76 | MP_SetEnvOption(env, MP_BUFFER_SIZE_OPT, pvm_getopt(PvmFragSize)); |
---|
77 | if ((env = MP_InitializeEnv(env)) == NULL) { |
---|
78 | fprintf(stderr, "%s: MP_EnvInitialize() failed!\n", argv[0]); |
---|
79 | exit(1); |
---|
80 | } |
---|
81 | MP_AddEnvTranspDevice(env, MP_PvmTransportDev, &pvm_ops); |
---|
82 | |
---|
83 | printf("MP buffer size is %d\n", MP_GetEnvOption(env, MP_BUFFER_SIZE_OPT)); |
---|
84 | printf("PVM buffer size is %d\n", pvm_getopt(PvmFragSize)); |
---|
85 | |
---|
86 | if ((link = MP_OpenLink(env, argc, argv)) == NULL) { |
---|
87 | MP_ReleaseEnv(env); |
---|
88 | pvm_exit(); |
---|
89 | fprintf(stderr, "%s: MP_OpenLink() failed!\n", argv[0]); |
---|
90 | exit(1); |
---|
91 | } |
---|
92 | |
---|
93 | MP_SetLinkOption(link, MP_LINK_LOG_MASK_OPT, MP_LOG_INIT_EVENTS); |
---|
94 | MP_SetLinkOption(link, MP_LINK_LOG_MASK_OPT, MP_LOG_READ_EVENTS); |
---|
95 | MP_SetLinkOption(link, MP_LINK_LOG_MASK_OPT, MP_LOG_WRITE_EVENTS); |
---|
96 | |
---|
97 | /* Wait for slave task to start up */ |
---|
98 | pvm_setopt(PvmRoute, PvmRouteDirect); |
---|
99 | pvm_recv(stid, 0); |
---|
100 | |
---|
101 | fd = fopen("/tmp/test.out", "w"); |
---|
102 | puts("Doing MP-PVM test\n"); |
---|
103 | |
---|
104 | printf("server's annotated tree(s):\n"); |
---|
105 | do { |
---|
106 | if (MP_TestEofMsg(link)) MP_SkipMsg(link); |
---|
107 | printf("\n\ntype\t\t #annots value\t#children\n"); |
---|
108 | /* STEP 1: get the request */ |
---|
109 | root = m_get_node(link); |
---|
110 | /* STEP 2: process the request */ |
---|
111 | more = process_request(root, fd); |
---|
112 | |
---|
113 | /* STEP 3: cleanup */ |
---|
114 | free_tree(root); /* free the annotated tree */ |
---|
115 | root = NULL; |
---|
116 | free_label_table(); /* free the label table */ |
---|
117 | } while (more); |
---|
118 | |
---|
119 | fflush(fd); fclose(fd); |
---|
120 | MP_CloseLink(link); |
---|
121 | MP_ReleaseEnv(env); |
---|
122 | printf("\nmaster: Successful termination.\n"); |
---|
123 | pvm_exit(); |
---|
124 | exit(0); |
---|
125 | |
---|
126 | bail: |
---|
127 | if (stid > 0) |
---|
128 | pvm_kill(stid); |
---|
129 | pvm_exit(); |
---|
130 | exit(1); |
---|
131 | } |
---|
132 | |
---|
133 | |
---|