source: git/MP/mp-pvm3/master.c @ 678cfd

spielwiese
Last change on this file since 678cfd was 678cfd, checked in by Olaf Bachmann <obachman@…>, 27 years ago
This commit was generated by cvs2svn to compensate for changes in r337, which included commits to RCS files with non-trunk default branches. git-svn-id: file:///usr/local/Singular/svn/trunk@338 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.1 KB
Line 
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#include "MP_PvmTransp.h"
20
21#define ENCODING  PvmDataRaw
22#define SLAVENAME "slave"
23
24EXTERN MP_TranspOps_t pvm_ops;
25
26FILE         *fd;
27
28#include "node.c"
29#include "mp_pvm.c"
30
31
32int 
33process_request(root, lfd)
34node_t *root;
35FILE *lfd;
36{
37  int more;
38
39    more = print_node(root, lfd);
40    return more;
41}
42
43main(argc, argv)
44        int argc;
45        char *argv[];
46{
47  int mytid;                  /* my task id */
48  int stid = 0;               /* slave task id */
49  int n, i, more = 0;
50  int spawn_flag = PvmTaskDefault;
51  char filename[128], *rhost = NULL;
52  MP_Env_pt  env = NULL;
53  MP_Link_pt link = NULL; 
54  node_t       *root = NULL;
55
56  pvm_setopt(PvmAutoErr, 0); /* tell PVM not to print error to stdout */
57  if ((mytid = pvm_mytid()) < 0) {
58                exit(1);
59  }
60
61  rhost = IMP_GetCmdlineArg(argc, argv, "-remhost");
62  if (rhost != NULL) spawn_flag = PvmTaskHost;
63  /* start up slave task */
64  if (pvm_spawn(SLAVENAME, argv, spawn_flag, rhost, 1, &stid) < 0 || stid < 0) {
65    fputs("can't initiate slave\n", stderr);
66    goto bail;
67  }
68
69  printf("name of data file: ");
70  scanf("%s", filename);
71
72  pvm_initsend(PvmDataDefault);
73  pvm_pkstr(filename);
74  pvm_send(stid, 5);
75
76  env = MP_AllocateEnv();
77  MP_SetEnvOption(env, MP_BUFFER_SIZE_OPT, pvm_getopt(PvmFragSize));
78  if ((env = MP_InitializeEnv(env)) == NULL) {
79    fprintf(stderr, "%s: MP_EnvInitialize() failed!\n", argv[0]);
80    exit(1);
81  }
82  MP_AddEnvTranspDevice(env, MP_PvmTransportDev, &pvm_ops);
83
84  printf("MP buffer size is %d\n", MP_GetEnvOption(env, MP_BUFFER_SIZE_OPT));
85  printf("PVM buffer size is %d\n", pvm_getopt(PvmFragSize));
86
87  if ((link = MP_OpenLink(env, argc, argv)) == NULL) {
88    MP_ReleaseEnv(env);
89    pvm_exit();
90    fprintf(stderr, "%s: MP_OpenLink() failed!\n", argv[0]);
91    exit(1);
92    }
93 
94  MP_SetLinkOption(link, MP_LINK_LOG_MASK_OPT, MP_LOG_INIT_EVENTS);
95  MP_SetLinkOption(link, MP_LINK_LOG_MASK_OPT, MP_LOG_READ_EVENTS);
96  MP_SetLinkOption(link, MP_LINK_LOG_MASK_OPT, MP_LOG_WRITE_EVENTS);
97
98    /* Wait for slave task to start up */
99  pvm_setopt(PvmRoute, PvmRouteDirect);
100  pvm_recv(stid, 0);
101
102  fd = fopen("/tmp/test.out", "w");
103  puts("Doing MP-PVM test\n");
104
105  printf("server's annotated tree(s):\n");
106  do {
107    if (MP_TestEofMsg(link))  MP_SkipMsg(link);
108    printf("\n\ntype\t\t  #annots      value\t#children\n");
109    /* STEP 1: get the request */
110       root = m_get_node(link);
111    /* STEP 2: process the request */
112       more = process_request(root, fd); 
113
114    /* STEP 3: cleanup */
115       free_tree(root);     /* free the annotated tree */
116       root = NULL; 
117       free_label_table();  /* free the label table    */
118  } while (more);
119
120  fflush(fd); fclose(fd);
121  MP_CloseLink(link);
122  MP_ReleaseEnv(env);
123  printf("\nmaster: Successful termination.\n");
124  pvm_exit();
125  exit(0);
126
127bail: 
128  if (stid > 0)
129    pvm_kill(stid);
130  pvm_exit();
131  exit(1);
132}
133
134
Note: See TracBrowser for help on using the repository browser.