1 | /* |
---|
2 | * put-vec.c |
---|
3 | * |
---|
4 | * See also get-vec.c |
---|
5 | */ |
---|
6 | |
---|
7 | #include <sys/types.h> |
---|
8 | #include <fcntl.h> |
---|
9 | #include <stdio.h> |
---|
10 | #include "pvm3.h" |
---|
11 | #include "MP.h" |
---|
12 | |
---|
13 | EXTERN MP_TranspOps_t pvm_ops; |
---|
14 | |
---|
15 | #define ENCODING PvmDataRaw |
---|
16 | #define SLAVENAME "get-vec" |
---|
17 | |
---|
18 | main(argc, argv) |
---|
19 | int argc; |
---|
20 | char *argv[]; |
---|
21 | { |
---|
22 | int mytid; /* my task id */ |
---|
23 | int spawn_flag = PvmTaskDefault; |
---|
24 | int stid, n = 0, i, *vec, numpts, numiter; |
---|
25 | char *rhost = NULL, *c = NULL; |
---|
26 | MP_Link_pt link = NULL; |
---|
27 | MP_Env_pt env = NULL; |
---|
28 | long start1, start2, end1, end2; |
---|
29 | FILE *fp; |
---|
30 | |
---|
31 | fp = fopen("mp-pvm.dat", "a"); |
---|
32 | |
---|
33 | pvm_setopt(PvmAutoErr, 0); /* tell PVM not to print error to stdout */ |
---|
34 | mytid = pvm_mytid(); /* enroll in pvm */ |
---|
35 | if ((c = IMP_GetCmdlineArg(argc, argv, "-iters")) == NULL){ |
---|
36 | fprintf(stderr, "missing -iters argument\n"); |
---|
37 | goto bail; |
---|
38 | } |
---|
39 | numiter = atoi(c); free(c); c = NULL; |
---|
40 | if ((c = IMP_GetCmdlineArg(argc, argv, "-pts")) == NULL){ |
---|
41 | fprintf(stderr, "missing -pts argument\n"); |
---|
42 | goto bail; |
---|
43 | } |
---|
44 | numpts = atoi(c); free(c); c = NULL; |
---|
45 | fprintf(stderr, "put-vec: numpts = %d, numiter = %d\n", numpts, numiter); |
---|
46 | fflush(stderr); |
---|
47 | fprintf(fp, "%4d \t %d \t %d \t ", numiter, numpts, numpts*sizeof(int)); |
---|
48 | |
---|
49 | vec = (int *)malloc(numpts * sizeof(int)); |
---|
50 | for (i = 0; i < numpts; i++) vec[i] = i; |
---|
51 | |
---|
52 | rhost = IMP_GetCmdlineArg(argc, argv, "-remhost"); |
---|
53 | if (rhost != NULL) spawn_flag = PvmTaskHost; |
---|
54 | /* start up slave task */ |
---|
55 | if (pvm_spawn(SLAVENAME, argv+1,spawn_flag, rhost, 1,&stid) < 0 || stid < 0) { |
---|
56 | fputs("can't initiate slave\n", stderr); |
---|
57 | goto bail; |
---|
58 | } |
---|
59 | |
---|
60 | env = MP_AllocateEnv(); |
---|
61 | MP_SetEnvOption(env, MP_BUFFER_SIZE_OPT, pvm_getopt(PvmFragSize)-4); |
---|
62 | env = MP_InitializeEnv(env); |
---|
63 | if (env == NULL) { |
---|
64 | fprintf(stderr, "%s: MP_InitializeEnv() failed!\n", argv[0]); |
---|
65 | exit(1); |
---|
66 | } |
---|
67 | MP_AddEnvTranspDevice(env, MP_PvmTransportDev, &pvm_ops); |
---|
68 | if ((link = MP_OpenLink(env, argc, argv)) == NULL) { |
---|
69 | fprintf(stderr, "%s: MP_OpenLink() failed!\n", argv[0]); |
---|
70 | exit(1); |
---|
71 | } |
---|
72 | /* MP_SetLinkOption(link, MP_LINK_LOG_MASK_OPT, MP_LOG_INIT_EVENTS); |
---|
73 | MP_SetLinkOption(link, MP_LINK_LOG_MASK_OPT, MP_LOG_WRITE_EVENTS); |
---|
74 | MP_SetLinkOption(link, MP_LINK_LOG_MASK_OPT, MP_LOG_READ_EVENTS); */ |
---|
75 | /* need the following to use PvmDataInPlace encoding mechanism */ |
---|
76 | /* MP_SetLinkOption(link, MP_LINK_SEND_MODE_OPT, MP_SEND_WHOLE_MSG); */ |
---|
77 | |
---|
78 | /* Wait for slave task to start up */ |
---|
79 | pvm_setopt(PvmRoute, PvmRouteDirect); |
---|
80 | pvm_recv( stid, 0 ); |
---|
81 | |
---|
82 | MP_PvmSetTids(link, 1, &stid); |
---|
83 | MP_PvmSetSendMode(link, PvmDataInPlace); |
---|
84 | clock(); |
---|
85 | |
---|
86 | for (i = 0; i < numiter; i++) { |
---|
87 | /* pvm_initsend(PvmDataInPlace); */ |
---|
88 | pvm_initsend(PvmDataRaw); |
---|
89 | pvm_pkint(vec, numpts, 1); |
---|
90 | if (pvm_send(stid, 0)) { |
---|
91 | fprintf(stderr, "can't send to \"%s\"\n", SLAVENAME); |
---|
92 | goto bail; |
---|
93 | } |
---|
94 | MP_ResetLink(link); |
---|
95 | pvm_recv( stid, 0 ); |
---|
96 | } |
---|
97 | end1 = clock(); |
---|
98 | for (i = 0; i < numiter; i++) { |
---|
99 | /* pvm_initsend(PvmDataRaw);*/ |
---|
100 | /* pvm_initsend(PvmDataInPlace);*/ |
---|
101 | if (IMP_PutSint32Vector(link, vec, numpts) != MP_Success) { |
---|
102 | fprintf(stderr, "put-vec: problem putting the vector\n"); |
---|
103 | MP_PrintError(link); |
---|
104 | } |
---|
105 | MP_EndMsg(link); |
---|
106 | /* if (pvm_send(stid, 0)) { |
---|
107 | fprintf(stderr, "can't send to \"%s\"\n", SLAVENAME); |
---|
108 | goto bail; |
---|
109 | } */ |
---|
110 | MP_ResetLink(link); |
---|
111 | pvm_recv( stid, 0 ); |
---|
112 | } |
---|
113 | end2 = clock(); |
---|
114 | fprintf(fp, "%14f\t", end1 / (float) numiter ); |
---|
115 | fprintf(fp, "%14f\n", (end2 - end1) / (float) numiter ); |
---|
116 | fflush(fp); |
---|
117 | printf("\nput-vec: Successful termination.\n"); |
---|
118 | fclose(fp); |
---|
119 | bail: |
---|
120 | free(vec); |
---|
121 | MP_CloseLink(link); /* cleanup and exit */ |
---|
122 | MP_ReleaseEnv(env); |
---|
123 | pvm_exit(); |
---|
124 | } |
---|