1 | /* |
---|
2 | * get-vec.c |
---|
3 | * |
---|
4 | * Receive a vector of integers from put-vec and return them. |
---|
5 | * |
---|
6 | */ |
---|
7 | |
---|
8 | #include <stdio.h> |
---|
9 | |
---|
10 | #include <sys/types.h> |
---|
11 | #include <fcntl.h> |
---|
12 | #include <stdio.h> |
---|
13 | #include <math.h> |
---|
14 | #include "pvm3.h" |
---|
15 | #include "MP.h" |
---|
16 | #include "MP_PvmTransp.h" |
---|
17 | |
---|
18 | EXTERN MP_TranspOps_t pvm_ops; |
---|
19 | |
---|
20 | #define ENCODING PvmDataRaw |
---|
21 | #define SIZE 1000 |
---|
22 | |
---|
23 | FILE *fd; |
---|
24 | |
---|
25 | main(argc, argv) |
---|
26 | int argc; |
---|
27 | char *argv[]; |
---|
28 | { |
---|
29 | int mytid; /* my task id */ |
---|
30 | int stid = 0; /* slave task id */ |
---|
31 | int n, i, more = 0, *vec = NULL, numpts, numiter; |
---|
32 | char filename[128], *c = NULL; |
---|
33 | MP_NumAnnot_t na = 0; |
---|
34 | MP_NumChild_t nc = SIZE; |
---|
35 | MP_Env_pt env = NULL; |
---|
36 | MP_Link_pt link = NULL; |
---|
37 | |
---|
38 | pvm_setopt(PvmAutoErr, 0); /* tell PVM not to print error to stdout */ |
---|
39 | /* pvm_setopt(PvmDebugMask, 3); */ |
---|
40 | pvm_setopt(PvmRoute, PvmRouteDirect); |
---|
41 | if ((mytid = pvm_mytid()) < 0) { |
---|
42 | exit(1); |
---|
43 | } |
---|
44 | if ((c = IMP_GetCmdlineArg(argc, argv, "-iters")) == NULL){ |
---|
45 | fprintf(stderr, "missing -iters argument\n"); |
---|
46 | goto bail; |
---|
47 | } |
---|
48 | numiter = atoi(c); free(c); c = NULL; |
---|
49 | if ((c = IMP_GetCmdlineArg(argc, argv, "-pts")) == NULL){ |
---|
50 | fprintf(stderr, "missing -pts argument\n"); |
---|
51 | goto bail; |
---|
52 | } |
---|
53 | numpts = atoi(c); free(c); c = NULL; |
---|
54 | fprintf(stderr, "get-vec: numpts = %d, numiter = %d\n", numpts, numiter); |
---|
55 | fflush(stderr); |
---|
56 | env = MP_AllocateEnv(); |
---|
57 | MP_SetEnvOption(env, MP_BUFFER_SIZE_OPT, pvm_getopt(PvmFragSize)-4); |
---|
58 | if ((env = MP_InitializeEnv(env)) == NULL) { |
---|
59 | fprintf(stderr, "%s: MP_EnvInitialize() failed!\n", argv[0]); |
---|
60 | exit(1); |
---|
61 | } |
---|
62 | MP_AddEnvTranspDevice(env, MP_PvmTransportDev, &pvm_ops); |
---|
63 | if ((link = MP_OpenLink(env, argc, argv)) == NULL) { |
---|
64 | fprintf(stderr, "%s: MP_OpenLink() failed!\n", argv[0]); |
---|
65 | exit(1); |
---|
66 | } |
---|
67 | /* MP_SetLinkOption(link, MP_LINK_LOG_MASK_OPT, MP_LOG_INIT_EVENTS); |
---|
68 | MP_SetLinkOption(link, MP_LINK_LOG_MASK_OPT, MP_LOG_READ_EVENTS); |
---|
69 | MP_SetLinkOption(link, MP_LINK_LOG_MASK_OPT, MP_LOG_WRITE_EVENTS); */ |
---|
70 | |
---|
71 | pvm_initsend(ENCODING); |
---|
72 | stid = pvm_parent(); |
---|
73 | pvm_send(stid, 0 ); /* let the parent know I am ready */ |
---|
74 | vec = IMP_MemAllocFnc(numpts * sizeof(int)); |
---|
75 | if (vec == NULL) fprintf(stderr, "ARGH!! vec is null!!\n"); |
---|
76 | /* fd = fopen("/tmp/test.out", "w"); */ |
---|
77 | for (i = 0; i < numiter; i++) { |
---|
78 | pvm_recv(-1, -1); |
---|
79 | if (pvm_upkint(vec, numpts, 1) < 0) |
---|
80 | pvm_perror("can't unpack the lousy array using pvm: "); |
---|
81 | |
---|
82 | pvm_initsend(ENCODING); |
---|
83 | pvm_send(stid, 0); |
---|
84 | } |
---|
85 | |
---|
86 | for (i = 0; i < numiter; i++) { |
---|
87 | if (MP_TestEofMsg(link)) { |
---|
88 | if (MP_SkipMsg(link) != MP_Success) { |
---|
89 | fprintf(stderr,"Problem with MP_SkipMsg()\n"); |
---|
90 | MP_PrintError(link); |
---|
91 | } |
---|
92 | } |
---|
93 | else if (MP_SkipMsg(link) != MP_Success) { |
---|
94 | fprintf(stderr,"Problem with MP_SkipMsg()\n"); |
---|
95 | MP_PrintError(link); |
---|
96 | } |
---|
97 | |
---|
98 | if (IMP_GetSint32Vector(link, &vec, numpts) != MP_Success) { |
---|
99 | fprintf(stderr,"Problem getting the vector with MP\n"); |
---|
100 | MP_PrintError(link); |
---|
101 | } |
---|
102 | |
---|
103 | pvm_initsend(ENCODING); |
---|
104 | pvm_send(stid, 0); /* let the parent know I am done */ |
---|
105 | } |
---|
106 | |
---|
107 | /* for (i = 0; i < numpts; i++) { |
---|
108 | if (!(i % 10)) fprintf(fd, "\n"); |
---|
109 | fprintf(fd, "%d ", vec[i]); |
---|
110 | } |
---|
111 | */ |
---|
112 | IMP_MemFreeFnc(vec, numpts * sizeof(int)); |
---|
113 | /* fflush(fd); fclose(fd); */ |
---|
114 | MP_CloseLink(link); |
---|
115 | MP_ReleaseEnv(env); |
---|
116 | printf("\nget-vec: Successful termination.\n"); |
---|
117 | bail: |
---|
118 | pvm_exit(); |
---|
119 | } |
---|
120 | |
---|
121 | |
---|