Annotation of OpenXM_contrib2/asir2000/io/ox.c, Revision 1.24
1.5 noro 1: /*
2: * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
3: * All rights reserved.
4: *
5: * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
6: * non-exclusive and royalty-free license to use, copy, modify and
7: * redistribute, solely for non-commercial and non-profit purposes, the
8: * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
9: * conditions of this Agreement. For the avoidance of doubt, you acquire
10: * only a limited right to use the SOFTWARE hereunder, and FLL or any
11: * third party developer retains all rights, including but not limited to
12: * copyrights, in and to the SOFTWARE.
13: *
14: * (1) FLL does not grant you a license in any way for commercial
15: * purposes. You may use the SOFTWARE only for non-commercial and
16: * non-profit purposes only, such as academic, research and internal
17: * business use.
18: * (2) The SOFTWARE is protected by the Copyright Law of Japan and
19: * international copyright treaties. If you make copies of the SOFTWARE,
20: * with or without modification, as permitted hereunder, you shall affix
21: * to all such copies of the SOFTWARE the above copyright notice.
22: * (3) An explicit reference to this SOFTWARE and its copyright owner
23: * shall be made on your publication or presentation in any form of the
24: * results obtained by use of the SOFTWARE.
25: * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.6 noro 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.5 noro 27: * for such modification or the source code of the modified part of the
28: * SOFTWARE.
29: *
30: * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
31: * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
32: * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
33: * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
34: * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
35: * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
36: * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
37: * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
38: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
39: * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
40: * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
41: * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
42: * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
43: * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
44: * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
45: * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
46: * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
1.24 ! noro 47: * $OpenXM: OpenXM_contrib2/asir2000/io/ox.c,v 1.23 2003/12/10 07:37:40 noro Exp $
1.5 noro 48: */
1.1 noro 49: #include "ca.h"
50: #include "parse.h"
1.3 noro 51: #include "signal.h"
1.1 noro 52: #include "wsio.h"
53: #include "ox.h"
54:
55: #define ISIZ sizeof(int)
56:
57: extern Obj VOIDobj;
58:
1.22 noro 59: extern int nserver_102, myrank_102;
1.1 noro 60: extern int ox_need_conv;
1.14 noro 61: int ox_usr1_sent, ox_int_received, critical_when_signal;
1.1 noro 62: unsigned int ox_serial;
63: int ox_flushing;
64: int ox_batch;
65: int ox_check=1;
1.2 noro 66: int ox_exchange_mathcap=1;
1.13 noro 67: JMP_BUF ox_env;
1.1 noro 68:
69: MATHCAP my_mathcap;
70:
71: struct oxcap {
72: unsigned int ox;
73: int ncap;
74: int *cap;
75: };
76:
77: struct mathcap {
78: LIST mc;
79: unsigned int version;
80: char *servername;
81: int nsmcap;
82: unsigned int *smcap;
83: int noxcap;
84: struct oxcap *oxcap;
85: };
86:
87: struct oxcap *my_oxcap;
88:
89: static struct mathcap my_mc;
90: static struct mathcap *remote_mc;
91: static int remote_mc_len;
92:
1.12 noro 93: void mclist_to_mc(LIST mclist,struct mathcap *mc);
94:
1.9 noro 95: #if defined(VISUAL)
96: /* XXX : mainly used in engine2000/io.c, but declared here */
97: HANDLE hStreamNotify,hStreamNotify_Ack;
98:
99: void cleanup_events()
100: {
101: /* ox_watch_stream may be waiting for hStreamNotify_Ack to be set */
102:
103: ResetEvent(hStreamNotify);
104: SetEvent(hStreamNotify_Ack);
105: }
106: #endif
107:
1.12 noro 108: void ox_resetenv(char *s)
1.1 noro 109: {
1.9 noro 110: #if defined(VISUAL)
111: cleanup_events();
112: #endif
1.1 noro 113: fprintf(stderr,"%s\n",s);
1.13 noro 114: LONGJMP(ox_env,1);
1.1 noro 115: }
116:
117: static int available_cmo[] = {
118: CMO_NULL, CMO_INT32, CMO_DATUM, CMO_STRING, CMO_MATHCAP,
119: CMO_ERROR, CMO_ERROR2, CMO_LIST, CMO_MONOMIAL32,
120: CMO_ZZ, CMO_QQ, CMO_ZERO,
121: CMO_DMS_GENERIC, CMO_DMS_OF_N_VARIABLES,
122: CMO_RING_BY_NAME, CMO_DISTRIBUTED_POLYNOMIAL,
123: CMO_RECURSIVE_POLYNOMIAL, CMO_UNIVARIATE_POLYNOMIAL,
124: CMO_INDETERMINATE,
1.11 noro 125: CMO_TREE,
1.1 noro 126: 0
127: };
128:
1.17 noro 129: static int asir_available_sm[] = {
130: SM_dupErrors, SM_getsp, SM_popSerializedLocalObject,
131: SM_popCMO, SM_popString, SM_pushCMOtag, SM_setName,
132: SM_evalName, SM_executeStringByLocalParser,
133: SM_executeStringByLocalParserInBatchMode,
134: SM_executeFunction, SM_shutdown, SM_pops,
135: SM_mathcap, SM_setMathcap, SM_nop,
136: SM_beginBlock, SM_endBlock,
137: 0
138: };
139:
1.15 noro 140: static int ox_asir_available_sm[] = {
1.1 noro 141: SM_dupErrors, SM_getsp, SM_popSerializedLocalObject,
1.7 noro 142: SM_popCMO, SM_popString, SM_pushCMOtag, SM_setName,
1.1 noro 143: SM_evalName, SM_executeStringByLocalParser,
144: SM_executeStringByLocalParserInBatchMode,
145: SM_executeFunction, SM_shutdown, SM_pops,
146: SM_mathcap, SM_setMathcap, SM_nop,
147: SM_beginBlock, SM_endBlock,
1.21 noro 148: SM_set_rank_102, SM_tcp_accept_102, SM_tcp_connect_102, SM_reset_102,
1.24 ! noro 149: SM_bcast_102, SM_reduce_102,
1.1 noro 150: 0
151: };
152:
1.15 noro 153: static int ox_plot_available_sm[] = {
154: SM_dupErrors, SM_getsp, SM_popSerializedLocalObject,
155: SM_popCMO, SM_popString, SM_setName,
156: SM_evalName, SM_executeStringByLocalParser,
157: SM_executeFunction, SM_shutdown, SM_pops,
1.16 noro 158: SM_mathcap, SM_setMathcap, SM_nop,
1.15 noro 159: 0
160: };
161:
1.1 noro 162: /*
163: mathcap =
164: [
165: version list,
166: SMlist,
167: [
168: [OX tag,CMO tag list],
169: [OX tag,CMO tag list],
170: ...
171: ]
172: ]
173: */
174:
175: void create_my_mathcap(char *system)
176: {
177: NODE n,n0;
178: int i,k;
179: STRING str;
1.12 noro 180: LIST sname,smlist,oxlist,cmolist,asirlist,oxasir,r;
1.1 noro 181: USINT tag,t,t1;
182:
183: if ( my_mathcap )
184: return;
185: /* version */
186: MKSTR(str,system);
187: MKUSINT(t,OX_VERSION);
188: n0 = mknode(2,t,str); MKLIST(sname,n0);
189:
1.15 noro 190: /* sm tag */
191: n0 = 0;
1.17 noro 192: if ( !strcmp(system,"asir") ) {
193: for ( i = 0; k = asir_available_sm[i]; i++ ) {
194: NEXTNODE(n0,n); MKUSINT(t,k); BDY(n) = (pointer)t;
195: }
196: } else if ( !strcmp(system,"ox_asir") ) {
1.15 noro 197: for ( i = 0; k = ox_asir_available_sm[i]; i++ ) {
198: NEXTNODE(n0,n); MKUSINT(t,k); BDY(n) = (pointer)t;
199: }
200: NEXT(n) = 0;
201: } else if ( !strcmp(system,"ox_plot") ) {
202: for ( i = 0; k = ox_plot_available_sm[i]; i++ ) {
203: NEXTNODE(n0,n); MKUSINT(t,k); BDY(n) = (pointer)t;
204: }
205: NEXT(n) = 0;
1.1 noro 206: }
1.15 noro 207: MKLIST(smlist,n0);
1.1 noro 208:
209: /* creation of [OX_DATA,CMO list] */
210: /* ox tag */
211: MKUSINT(tag,OX_DATA);
212: /* cmo tag */
213: for ( n0 = 0, i = 0; k = available_cmo[i]; i++ ) {
214: NEXTNODE(n0,n); MKUSINT(t,k); BDY(n) = (pointer)t;
215: }
216: NEXT(n) = 0; MKLIST(cmolist,n0);
217: /* [ox tag, cmo list] */
218: n0 = mknode(2,tag,cmolist);
219: MKLIST(oxlist,n0);
220:
221: /* creation of [OX_LOCAL_OBJECT_ASIR,ASIR tag] */
222: /* ox tag */
223: MKUSINT(tag,OX_LOCAL_OBJECT_ASIR);
224: /* local tag */
225: MKUSINT(t,ASIR_VL);
226: MKUSINT(t1,ASIR_OBJ);
227: n0 = mknode(2,t,t1); MKLIST(cmolist,n0);
228: /* [ox tag, local list] */
229: n0 = mknode(2,tag,cmolist);
230: MKLIST(asirlist,n0);
231:
232: /* [oxlist,asirlist] */
233: n0 = mknode(2,oxlist,asirlist); MKLIST(oxasir,n0);
234:
235: /* [version,sm,oxasir] */
236: n0 = mknode(3,sname,smlist,oxasir); MKLIST(r,n0);
237:
238: MKMATHCAP(my_mathcap,r);
239: mclist_to_mc(r,&my_mc);
240: my_oxcap = my_mc.oxcap;
241: }
242:
243: void store_remote_mathcap(int s,MATHCAP mc)
244: {
245: if ( !remote_mc ) {
246: remote_mc_len = 16;
247: remote_mc = (struct mathcap *)
248: CALLOC(remote_mc_len,sizeof(struct mathcap));
249: }
250: if ( s >= remote_mc_len ) {
251: remote_mc_len *= 2;
252: remote_mc = (struct mathcap *)REALLOC(remote_mc,
253: remote_mc_len*sizeof(struct mathcap));
254: }
255: mclist_to_mc(BDY(mc),&remote_mc[s]);
256: }
257:
258: /*
259: mathcap =
260: [
261: version list,
262: SMlist,
263: [
264: [OX tag,CMO tag list],
265: [OX tag,CMO tag list],
266: ...
267: ]
268: ]
269:
270: ===>
271:
272: mathcap
273: | version | &servername | nsmcap | &smcap | noxcap | &oxcap |
274: smcap
275: | SM_xxx | SM_yyy | ... |
276: oxcap
277: | oxcap[0] | oxcap[1] | ... |
278: oxcap[i]
279: | ox | ncap | &cap |
280: cap
281: | CMO_xxx | CMO_yyy | ... |
282: */
283:
284: void mclist_to_mc(LIST mclist,struct mathcap *mc)
285: {
1.12 noro 286: int l,i,j;
287: NODE n,t,oxcmo,cap;
1.1 noro 288: int *ptr;
289:
290: /*
291: [
292: [ version,servername ]
293: [sm1,sm2,...],
294: [
295: [o1,[n11,n12,...]],
296: [o2,[n21,n22,...]],
297: ...
298: ]
299: ]
300: */
301: n = BDY(mclist);
302: mc->mc = mclist;
303: mc->version = BDY((USINT)BDY(BDY((LIST)BDY(n))));
304: mc->servername = BDY((STRING)BDY(NEXT(BDY((LIST)BDY(n)))));
305:
306: /* smcap */
307: n = NEXT(n);
308: t = BDY((LIST)BDY(n));
309: mc->nsmcap = length(t);
310: mc->smcap = (int *)MALLOC_ATOMIC(mc->nsmcap*sizeof(int));
311: for ( j = 0, ptr = mc->smcap; j < mc->nsmcap; j++, t = NEXT(t) )
312: ptr[j] = BDY((USINT)BDY(t));
313:
314: n = NEXT(n);
315: n = BDY((LIST)BDY(n));
316: /* n -> BDY([[OX1,CMOlist1], [OX2,CMOlist2], ...]) */
317: mc->noxcap = length(n);
318: mc->oxcap = (struct oxcap *)MALLOC(mc->noxcap*sizeof(struct oxcap));
319: for ( j = 0; j < mc->noxcap; j++, n = NEXT(n) ) {
320: oxcmo = BDY((LIST)BDY(n));
321: /* oxcmo = BDY([OXj,CMOlistj]) */
322: mc->oxcap[j].ox = BDY((USINT)BDY(oxcmo));
323: cap = BDY((LIST)BDY(NEXT(oxcmo)));
324: /* cap ->BDY(CMOlistj) */
325: l = length(cap);
326: mc->oxcap[j].ncap = l;
327: mc->oxcap[j].cap = (unsigned int *)CALLOC(l+1,sizeof(unsigned int));
328: for ( t = cap, ptr = mc->oxcap[j].cap, i = 0; i < l; t = NEXT(t), i++ )
329: ptr[i] = BDY((USINT)BDY(t));
330: }
331: }
332:
1.12 noro 333: int check_sm_by_mc(int s,unsigned int smtag)
1.1 noro 334: {
335: struct mathcap *rmc;
336: int nsmcap,i;
337: unsigned int *smcap;
338:
339: /* XXX : return 1 if remote_mc is not available. */
340: if ( !remote_mc )
341: return 1;
342: rmc = &remote_mc[s];
343: nsmcap = rmc->nsmcap;
344: smcap = rmc->smcap;
345: if ( !smcap )
346: return 1;
347: for ( i = 0; i < nsmcap; i++ )
348: if ( smcap[i] == smtag )
349: break;
350: if ( i == nsmcap )
351: return 0;
352: else
353: return 1;
354: }
355:
1.12 noro 356: int check_by_mc(int s,unsigned int oxtag,unsigned int cmotag)
1.1 noro 357: {
358: struct mathcap *rmc;
359: int noxcap,ncap,i,j;
360: struct oxcap *oxcap;
361: unsigned int *cap;
362:
363: /* XXX : return 1 if remote_mc is not available. */
364: if ( !remote_mc )
365: return 1;
366: rmc = &remote_mc[s];
367: noxcap = rmc->noxcap;
368: oxcap = rmc->oxcap;
369: if ( !oxcap )
370: return 1;
371: for ( i = 0; i < noxcap; i++ )
372: if ( oxcap[i].ox == oxtag )
373: break;
374: if ( i == noxcap )
375: return 0;
376: ncap = oxcap[i].ncap;
377: cap = oxcap[i].cap;
378: for ( j = 0; j < ncap; j++ )
379: if ( cap[j] == cmotag )
380: break;
381: if ( j == ncap )
382: return 0;
383: else
384: return 1;
385: }
386:
387: void begin_critical() {
388: critical_when_signal = 1;
389: }
390:
391: void end_critical() {
392: critical_when_signal = 0;
393: if ( ox_usr1_sent ) {
1.12 noro 394: ox_usr1_sent = 0;
395: #if !defined(VISUAL)
396: ox_usr1_handler(SIGUSR1);
397: #else
398: ox_usr1_handler(0);
399: #endif
1.1 noro 400: }
401: if ( ox_int_received ) {
402: ox_int_received = 0; int_handler(SIGINT);
403: }
404: }
405:
1.18 noro 406: extern FUNC registered_handler;
407:
1.12 noro 408: void ox_usr1_handler(int sig)
1.1 noro 409: {
410: #if !defined(VISUAL)
411: signal(SIGUSR1,ox_usr1_handler);
412: #endif
413: if ( critical_when_signal ) {
414: fprintf(stderr,"usr1 : critical\n");
415: ox_usr1_sent = 1;
416: } else {
417: ox_flushing = 1;
1.18 noro 418: if ( registered_handler ) {
419: fprintf(stderr,
420: "usr1 : calling the registered exception handler...");
421: bevalf(registered_handler,0);
422: fprintf(stderr, "done.\n");
423: }
1.1 noro 424: ox_resetenv("usr1 : return to toplevel by SIGUSR1");
425: }
426: }
427:
428: void clear_readbuffer()
429: {
430: #if defined(linux)
431: iofp[0].in->_IO_read_ptr = iofp[0].in->_IO_read_end;
432: #elif defined(__FreeBSD__)
433: fpurge(iofp[0].in);
434: #endif
435: /*
436: sock = fileno(iofp[0].in);
437: interval.tv_sec = (int)0;
438: interval.tv_usec = (int)0;
439:
440: FD_ZERO(&r); FD_ZERO(&w); FD_ZERO(&e);
441: FD_SET(sock,&r);
442: while ( 1 ) {
443: n = select(FD_SETSIZE,&r,&w,&e,&interval);
444: if ( !n )
445: break;
446: read(sock,&c,1);
447: }
448: */
449: }
450:
1.20 noro 451: #if MPI
1.1 noro 452: int ox_data_is_available(int s)
453: {
454: return 1;
455: }
456:
457: void wait_for_data(int s)
458: {
459: return;
460: }
461: #else
462: int ox_data_is_available(int s)
463: {
464: return FP_DATA_IS_AVAILABLE(iofp[s].in);
465: }
466:
467: void wait_for_data(int s)
468: {
469: fd_set r;
470: int sock;
471:
472: if ( !FP_DATA_IS_AVAILABLE(iofp[s].in) ) {
473: #if defined(VISUAL)
474: sock = iofp[s].in->fildes;
475: FD_ZERO(&r);
1.12 noro 476: FD_SET((unsigned int)sock,&r);
1.1 noro 477: select(0,&r,NULL,NULL,NULL);
478: #else
479: sock = fileno(iofp[s].in);
480: FD_ZERO(&r);
481: FD_SET(sock,&r);
482: select(FD_SETSIZE,&r,NULL,NULL,NULL);
483: #endif
484: }
485: }
1.21 noro 486:
487: void wait_for_data_102(int rank)
488: {
489: fd_set r;
490: int sock;
491:
492: if ( !FP_DATA_IS_AVAILABLE(iofp_102[rank].in) ) {
493: #if defined(VISUAL)
494: sock = iofp_102[rank].in->fildes;
495: FD_ZERO(&r);
496: FD_SET((unsigned int)sock,&r);
497: select(0,&r,NULL,NULL,NULL);
498: #else
499: sock = fileno(iofp_102[rank].in);
500: FD_ZERO(&r);
501: FD_SET(sock,&r);
502: select(FD_SETSIZE,&r,NULL,NULL,NULL);
503: #endif
504: }
505: }
1.1 noro 506: #endif
507:
508: void ox_send_data(int s,pointer p)
509: {
1.8 noro 510: ERR err;
511:
512: if ( ox_check && !ox_check_cmo(s,(Obj)p) ) {
513: create_error(&err,ox_serial,"ox_send_data : Mathcap violation");
514: p = (pointer)err;
515: }
1.1 noro 516: begin_critical();
517: ox_write_int(s,OX_DATA);
518: ox_write_int(s,ox_serial++);
519: ox_write_cmo(s,p);
520: ox_flush_stream(s);
521: end_critical();
522: }
523:
1.21 noro 524: void ox_send_data_102(int rank,pointer p)
525: {
526: ERR err;
527:
528: begin_critical();
529: ox_write_int_102(rank,OX_DATA);
530: ox_write_int_102(rank,ox_serial++);
531: ox_write_cmo_102(rank,p);
532: ox_flush_stream_102(rank);
533: end_critical();
1.22 noro 534: }
535:
1.24 ! noro 536: void ox_bcast_102(int root)
1.22 noro 537: {
538: Obj data;
1.23 noro 539: int r,mask,id,src,dst;
1.22 noro 540:
1.23 noro 541: r = myrank_102-root;
1.24 ! noro 542: if ( r == 0 )
! 543: data = (Obj)asir_pop_one();
! 544:
1.23 noro 545: if ( r < 0 ) r += nserver_102;
546: for ( mask = 1; mask < nserver_102; mask <<= 1 )
1.22 noro 547: if ( r&mask ) {
1.23 noro 548: src = myrank_102-mask;
549: if ( src < 0 ) src += nserver_102;
1.22 noro 550: ox_recv_102(src,&id,&data);
551: break;
552: }
553: for ( mask >>= 1; mask > 0; mask >>= 1 )
1.23 noro 554: if ( (r+mask) < nserver_102 ) {
555: dst = myrank_102+mask;
556: if ( dst >= nserver_102 ) dst -= nserver_102;
1.22 noro 557: ox_send_data_102(dst,data);
558: }
1.24 ! noro 559: asir_push_one(data);
1.23 noro 560: }
561:
562: /* func : an arithmetic funcion func(vl,a,b,*c) */
563:
1.24 ! noro 564: void ox_reduce_102(int root,void (*func)())
1.23 noro 565: {
1.24 ! noro 566: Obj data,data0,t;
1.23 noro 567: int r,mask,id,src,dst;
568:
569: r = myrank_102-root;
570: if ( r < 0 ) r += nserver_102;
1.24 ! noro 571: data = (Obj)asir_pop_one();
1.23 noro 572: for ( mask = 1; mask < nserver_102; mask <<= 1 )
573: if ( r&mask ) {
574: dst = (r-mask)+root;
575: if ( dst >= nserver_102 ) dst -= nserver_102;
576: ox_send_data_102(dst,data);
577: break;
578: } else {
579: src = r+mask;
580: if ( src < nserver_102 ) {
581: src += root;
582: if ( src >= nserver_102 ) src -= nserver_102;
583: ox_recv_102(src,&id,&data0);
584: (*func)(CO,data,data0,&t); data = t;
585: }
586: }
1.24 ! noro 587: asir_push_one(r?0:data);
1.21 noro 588: }
589:
1.1 noro 590: void ox_send_cmd(int s,int id)
591: {
592: if ( ox_check && !check_sm_by_mc(s,id) )
593: error("ox_send_cmd : Mathcap violation");
594: begin_critical();
595: ox_write_int(s,OX_COMMAND);
596: ox_write_int(s,ox_serial++);
597: ox_write_int(s,id);
598: ox_flush_stream(s);
599: end_critical();
600: }
601:
602: void ox_send_sync(int s)
603: {
604: begin_critical();
605: ox_write_int(s,OX_SYNC_BALL);
606: ox_write_int(s,ox_serial++);
607: ox_flush_stream(s);
608: end_critical();
609: }
610:
1.21 noro 611: void ox_send_sync_102(int rank)
612: {
613: begin_critical();
614: ox_write_int_102(rank,OX_SYNC_BALL);
615: ox_write_int_102(rank,ox_serial++);
616: ox_flush_stream_102(rank);
617: end_critical();
618: }
619:
1.1 noro 620: void ox_send_local_data(int s,Obj p)
621: {
622: begin_critical();
623: ox_write_int(s,OX_LOCAL_OBJECT_ASIR);
624: ox_write_int(s,ox_serial++);
625: ox_write_int(s,ASIR_OBJ);
1.12 noro 626: saveobj((FILE *)iofp[s].out,p);
1.1 noro 627: ox_flush_stream(s);
628: end_critical();
629: }
630:
1.21 noro 631: void ox_send_local_data_102(int rank,Obj p)
632: {
633: begin_critical();
634: ox_write_int_102(rank,OX_LOCAL_OBJECT_ASIR);
635: ox_write_int_102(rank,ox_serial++);
636: ox_write_int_102(rank,ASIR_OBJ);
637: saveobj((FILE *)iofp_102[rank].out,p);
638: ox_flush_stream_102(rank);
639: end_critical();
640: }
641:
1.1 noro 642: void ox_send_local_ring(int s,VL vl)
643: {
644: begin_critical();
645: ox_write_int(s,OX_LOCAL_OBJECT_ASIR);
646: ox_write_int(s,ox_serial++);
647: ox_write_int(s,ASIR_VL);
1.12 noro 648: savevl((FILE *)iofp[s].out,vl);
1.1 noro 649: ox_flush_stream(s);
650: end_critical();
651: }
652:
1.21 noro 653: void ox_send_local_ring_102(int rank,VL vl)
654: {
655: begin_critical();
656: ox_write_int_102(rank,OX_LOCAL_OBJECT_ASIR);
657: ox_write_int_102(rank,ox_serial++);
658: ox_write_int_102(rank,ASIR_VL);
659: savevl((FILE *)iofp_102[rank].out,vl);
660: ox_flush_stream_102(rank);
661: end_critical();
662: }
663:
1.12 noro 664: unsigned int ox_recv(int s, int *id, Obj *p)
1.1 noro 665: {
666: unsigned int cmd,serial;
667: USINT ui;
668:
669: wait_for_data(s);
670: begin_critical();
671: ox_read_int(s,id);
672: ox_read_int(s,&serial);
673: switch ( *id ) {
674: case OX_COMMAND:
675: ox_read_int(s,&cmd);
676: MKUSINT(ui,cmd);
1.12 noro 677: *p = (Obj)ui;
1.1 noro 678: break;
679: case OX_DATA:
680: ox_read_cmo(s,p);
681: break;
682: case OX_LOCAL_OBJECT_ASIR:
683: ox_read_local(s,p);
684: break;
685: default:
686: *p = 0;
687: break;
688: }
689: end_critical();
690: return serial;
691: }
692:
1.21 noro 693: unsigned int ox_recv_102(int rank, int *id, Obj *p)
694: {
695: unsigned int cmd,serial;
696: USINT ui;
697:
698: wait_for_data_102(rank);
699: begin_critical();
700: ox_read_int_102(rank,id);
701: ox_read_int_102(rank,&serial);
702: switch ( *id ) {
703: case OX_COMMAND:
704: ox_read_int_102(rank,&cmd);
705: MKUSINT(ui,cmd);
706: *p = (Obj)ui;
707: break;
708: case OX_DATA:
709: ox_read_cmo_102(rank,p);
710: break;
711: case OX_LOCAL_OBJECT_ASIR:
712: ox_read_local_102(rank,p);
713: break;
714: default:
715: *p = 0;
716: break;
717: }
718: end_critical();
719: return serial;
720: }
721:
1.12 noro 722: void ox_get_result(int s,Obj *rp)
1.1 noro 723: {
724: int id;
725: Obj obj,r;
726: int level;
727:
728: level = 0;
729: r = 0;
730: do {
1.12 noro 731: ox_recv(s,&id,&obj);
1.1 noro 732: if ( id == OX_COMMAND ) {
733: switch ( ((USINT)obj)->body ) {
734: case SM_beginBlock:
735: level++;
736: break;
737: case SM_endBlock:
738: level--;
739: }
740: } else
741: r = obj;
742: } while ( level );
743: *rp = r;
744: }
745:
746: void ox_read_int(int s, int *n)
747: {
748: ox_need_conv = iofp[s].conv;
1.12 noro 749: read_int((FILE *)iofp[s].in,n);
1.1 noro 750: }
751:
1.21 noro 752: void ox_read_int_102(int rank, int *n)
753: {
754: ox_need_conv = iofp_102[rank].conv;
755: read_int((FILE *)iofp_102[rank].in,n);
756: }
757:
1.1 noro 758: void ox_read_cmo(int s, Obj *rp)
759: {
760: ox_need_conv = iofp[s].conv;
1.12 noro 761: read_cmo((FILE *)iofp[s].in,rp);
1.1 noro 762: }
763:
1.21 noro 764: void ox_read_cmo_102(int rank, Obj *rp)
765: {
766: ox_need_conv = iofp_102[rank].conv;
767: read_cmo((FILE *)iofp_102[rank].in,rp);
768: }
769:
770:
1.1 noro 771: void ox_read_local(int s, Obj *rp)
772: {
773: int id;
774:
775: ox_need_conv = iofp[s].conv;
1.12 noro 776: read_int((FILE *)iofp[s].in,&id);
1.1 noro 777: switch ( id ) {
778: case ASIR_VL:
1.12 noro 779: loadvl((FILE *)iofp[s].in);
1.1 noro 780: *rp = VOIDobj;
781: break;
782: case ASIR_OBJ:
1.12 noro 783: loadobj((FILE *)iofp[s].in,rp);
1.1 noro 784: break;
785: default:
786: error("ox_read_local : unsupported id");
787: break;
788: }
789: }
790:
1.21 noro 791: void ox_read_local_102(int rank, Obj *rp)
792: {
793: int id;
794:
795: ox_need_conv = iofp_102[rank].conv;
796: read_int((FILE *)iofp_102[rank].in,&id);
797: switch ( id ) {
798: case ASIR_VL:
799: loadvl((FILE *)iofp_102[rank].in);
800: *rp = VOIDobj;
801: break;
802: case ASIR_OBJ:
803: loadobj((FILE *)iofp_102[rank].in,rp);
804: break;
805: default:
806: error("ox_read_local_102 : unsupported id");
807: break;
808: }
809: }
810:
1.1 noro 811: void ox_write_int(int s, int n)
812: {
813: ox_need_conv = iofp[s].conv;
1.12 noro 814: write_int((FILE *)iofp[s].out,&n);
1.1 noro 815: }
816:
1.21 noro 817: void ox_write_int_102(int rank, int n)
818: {
819: ox_need_conv = iofp_102[rank].conv;
820: write_int((FILE *)iofp_102[rank].out,&n);
821: }
822:
1.1 noro 823: void ox_write_cmo(int s, Obj obj)
824: {
825: ox_need_conv = iofp[s].conv;
1.12 noro 826: write_cmo((FILE *)iofp[s].out,obj);
1.1 noro 827: }
828:
1.21 noro 829: void ox_write_cmo_102(int rank, Obj obj)
830: {
831: ox_need_conv = iofp_102[rank].conv;
832: write_cmo((FILE *)iofp_102[rank].out,obj);
833: }
834:
1.1 noro 835: int ox_check_cmo(int s, Obj obj)
836: {
837: NODE m;
838:
839: if ( !obj )
840: return 1;
841: switch ( OID(obj) ) {
842: case O_MATHCAP: case O_STR: case O_ERR: case O_USINT: case O_VOID:
1.10 noro 843: case O_BYTEARRAY:
1.1 noro 844: return 1;
845: case O_P:
846: if ( !check_by_mc(s,OX_DATA,CMO_RECURSIVE_POLYNOMIAL) )
847: return 0;
848: else
849: return ox_check_cmo_p(s,(P)obj);
850: case O_R:
851: if ( !check_by_mc(s,OX_DATA,CMO_RATIONAL) )
852: return 0;
853: else if ( !check_by_mc(s,OX_DATA,CMO_RECURSIVE_POLYNOMIAL) )
854: return 0;
855: else
856: return ox_check_cmo_p(s,NM((R)obj)) && ox_check_cmo_p(s,DN((R)obj));
857: case O_DP:
858: return ox_check_cmo_dp(s,(DP)obj);
859: case O_N:
1.4 noro 860: switch ( NID((Num)obj) ) {
861: case N_Q:
862: if ( INT((Q)obj) )
863: return check_by_mc(s,OX_DATA,CMO_ZZ);
864: else
865: return check_by_mc(s,OX_DATA,CMO_QQ);
866: case N_R:
867: return 1;
868: default:
869: return 0;
870: }
871: break;
1.1 noro 872: case O_LIST:
873: for ( m = BDY((LIST)obj); m; m = NEXT(m) )
874: if ( !ox_check_cmo(s,(BDY(m))) )
875: return 0;
1.11 noro 876: return 1;
877: case O_QUOTE: /* XXX */
1.1 noro 878: return 1;
879: default:
880: return 0;
881: }
882: }
883:
884: void ox_get_serverinfo(int s, LIST *rp)
885: {
886: if ( remote_mc )
887: *rp = remote_mc[s].mc;
888: else {
889: MKLIST(*rp,0);
890: }
891: }
1.15 noro 892:
893: char *ox_get_servername(int s)
894: {
895: return (remote_mc && remote_mc[s].servername)?remote_mc[s].servername:0;
896: }
897:
1.1 noro 898:
899: int ox_check_cmo_p(int s, P p)
900: {
901: DCP dc;
902:
903: if ( NUM(p) )
904: return ox_check_cmo(s,(Obj)p);
905: else {
906: for ( dc = DC(p); dc; dc = NEXT(dc) )
907: if ( !ox_check_cmo_p(s,COEF(dc)) )
908: return 0;
909: return 1;
910: }
911: }
912:
913: int ox_check_cmo_dp(int s, DP p)
914: {
915: MP m;
916:
917: for ( m = BDY(p); m; m = NEXT(m) )
918: if ( !ox_check_cmo(s,(Obj)m->c) )
919: return 0;
920: return 1;
921: }
922:
1.12 noro 923: void ox_flush_stream(int s)
1.1 noro 924: {
925: if ( ox_batch )
926: return;
927: #if defined(VISUAL)
928: if ( _fileno(&iofp[s].out->fp) < 0 )
929: cflush(iofp[s].out);
930: else
1.20 noro 931: #elif MPI
1.1 noro 932: if ( (char)fileno(&iofp[s].out->fp) < 0 )
933: cflush(iofp[s].out);
934: else
935: #endif
1.12 noro 936: fflush((FILE *)iofp[s].out);
1.1 noro 937: }
938:
1.12 noro 939: void ox_flush_stream_force(int s)
1.1 noro 940: {
941: #if defined(VISUAL)
942: if ( _fileno(&iofp[s].out->fp) < 0 )
943: cflush(iofp[s].out);
944: else
1.20 noro 945: #elif MPI
1.1 noro 946: if ( (char)fileno(&iofp[s].out->fp) < 0 )
947: cflush(iofp[s].out);
948: else
949: #endif
1.12 noro 950: fflush((FILE *)iofp[s].out);
1.21 noro 951: }
952:
953: void ox_flush_stream_102(int rank)
954: {
955: if ( !ox_batch )
956: ox_flush_stream_force_102(rank);
957: }
958:
959: void ox_flush_stream_force_102(int rank)
960: {
961: if ( iofp_102[rank].out )
962: #if defined(VISUAL)
963: cflush(iofp_102[rank].out);
964: #elif MPI
965: cflush(iofp_102[rank].out);
966: #else
967: fflush(iofp_102[rank].out);
968: #endif
1.1 noro 969: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>