Annotation of OpenXM_contrib2/asir2000/io/ox.c, Revision 1.29
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.29 ! noro 47: * $OpenXM: OpenXM_contrib2/asir2000/io/ox.c,v 1.28 2009/02/13 11:25:48 ohara 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,
1.25 takayama 123: CMO_RATIONAL,
1.1 noro 124: CMO_RECURSIVE_POLYNOMIAL, CMO_UNIVARIATE_POLYNOMIAL,
125: CMO_INDETERMINATE,
1.11 noro 126: CMO_TREE,
1.1 noro 127: 0
128: };
129:
1.17 noro 130: static int asir_available_sm[] = {
131: SM_dupErrors, SM_getsp, SM_popSerializedLocalObject,
132: SM_popCMO, SM_popString, SM_pushCMOtag, SM_setName,
133: SM_evalName, SM_executeStringByLocalParser,
134: SM_executeStringByLocalParserInBatchMode,
135: SM_executeFunction, SM_shutdown, SM_pops,
136: SM_mathcap, SM_setMathcap, SM_nop,
137: SM_beginBlock, SM_endBlock,
138: 0
139: };
140:
1.15 noro 141: static int ox_asir_available_sm[] = {
1.1 noro 142: SM_dupErrors, SM_getsp, SM_popSerializedLocalObject,
1.7 noro 143: SM_popCMO, SM_popString, SM_pushCMOtag, SM_setName,
1.1 noro 144: SM_evalName, SM_executeStringByLocalParser,
145: SM_executeStringByLocalParserInBatchMode,
146: SM_executeFunction, SM_shutdown, SM_pops,
147: SM_mathcap, SM_setMathcap, SM_nop,
1.29 ! noro 148: SM_beginBlock, SM_endBlock, SM_executeFunctionSync,
1.21 noro 149: SM_set_rank_102, SM_tcp_accept_102, SM_tcp_connect_102, SM_reset_102,
1.24 noro 150: SM_bcast_102, SM_reduce_102,
1.1 noro 151: 0
152: };
153:
1.15 noro 154: static int ox_plot_available_sm[] = {
155: SM_dupErrors, SM_getsp, SM_popSerializedLocalObject,
156: SM_popCMO, SM_popString, SM_setName,
157: SM_evalName, SM_executeStringByLocalParser,
158: SM_executeFunction, SM_shutdown, SM_pops,
1.16 noro 159: SM_mathcap, SM_setMathcap, SM_nop,
1.15 noro 160: 0
161: };
162:
1.1 noro 163: /*
164: mathcap =
165: [
166: version list,
167: SMlist,
168: [
169: [OX tag,CMO tag list],
170: [OX tag,CMO tag list],
171: ...
172: ]
173: ]
174: */
175:
176: void create_my_mathcap(char *system)
177: {
178: NODE n,n0;
179: int i,k;
180: STRING str;
1.12 noro 181: LIST sname,smlist,oxlist,cmolist,asirlist,oxasir,r;
1.1 noro 182: USINT tag,t,t1;
183:
184: if ( my_mathcap )
185: return;
186: /* version */
187: MKSTR(str,system);
188: MKUSINT(t,OX_VERSION);
189: n0 = mknode(2,t,str); MKLIST(sname,n0);
190:
1.15 noro 191: /* sm tag */
192: n0 = 0;
1.17 noro 193: if ( !strcmp(system,"asir") ) {
194: for ( i = 0; k = asir_available_sm[i]; i++ ) {
195: NEXTNODE(n0,n); MKUSINT(t,k); BDY(n) = (pointer)t;
196: }
197: } else if ( !strcmp(system,"ox_asir") ) {
1.15 noro 198: for ( i = 0; k = ox_asir_available_sm[i]; i++ ) {
199: NEXTNODE(n0,n); MKUSINT(t,k); BDY(n) = (pointer)t;
200: }
201: NEXT(n) = 0;
202: } else if ( !strcmp(system,"ox_plot") ) {
203: for ( i = 0; k = ox_plot_available_sm[i]; i++ ) {
204: NEXTNODE(n0,n); MKUSINT(t,k); BDY(n) = (pointer)t;
205: }
206: NEXT(n) = 0;
1.1 noro 207: }
1.15 noro 208: MKLIST(smlist,n0);
1.1 noro 209:
210: /* creation of [OX_DATA,CMO list] */
211: /* ox tag */
212: MKUSINT(tag,OX_DATA);
213: /* cmo tag */
214: for ( n0 = 0, i = 0; k = available_cmo[i]; i++ ) {
215: NEXTNODE(n0,n); MKUSINT(t,k); BDY(n) = (pointer)t;
216: }
217: NEXT(n) = 0; MKLIST(cmolist,n0);
218: /* [ox tag, cmo list] */
219: n0 = mknode(2,tag,cmolist);
220: MKLIST(oxlist,n0);
221:
222: /* creation of [OX_LOCAL_OBJECT_ASIR,ASIR tag] */
223: /* ox tag */
224: MKUSINT(tag,OX_LOCAL_OBJECT_ASIR);
225: /* local tag */
226: MKUSINT(t,ASIR_VL);
227: MKUSINT(t1,ASIR_OBJ);
228: n0 = mknode(2,t,t1); MKLIST(cmolist,n0);
229: /* [ox tag, local list] */
230: n0 = mknode(2,tag,cmolist);
231: MKLIST(asirlist,n0);
232:
233: /* [oxlist,asirlist] */
234: n0 = mknode(2,oxlist,asirlist); MKLIST(oxasir,n0);
235:
236: /* [version,sm,oxasir] */
237: n0 = mknode(3,sname,smlist,oxasir); MKLIST(r,n0);
238:
239: MKMATHCAP(my_mathcap,r);
240: mclist_to_mc(r,&my_mc);
241: my_oxcap = my_mc.oxcap;
242: }
243:
244: void store_remote_mathcap(int s,MATHCAP mc)
245: {
246: if ( !remote_mc ) {
247: remote_mc_len = 16;
248: remote_mc = (struct mathcap *)
249: CALLOC(remote_mc_len,sizeof(struct mathcap));
250: }
251: if ( s >= remote_mc_len ) {
252: remote_mc_len *= 2;
253: remote_mc = (struct mathcap *)REALLOC(remote_mc,
254: remote_mc_len*sizeof(struct mathcap));
255: }
256: mclist_to_mc(BDY(mc),&remote_mc[s]);
257: }
258:
259: /*
260: mathcap =
261: [
262: version list,
263: SMlist,
264: [
265: [OX tag,CMO tag list],
266: [OX tag,CMO tag list],
267: ...
268: ]
269: ]
270:
271: ===>
272:
273: mathcap
274: | version | &servername | nsmcap | &smcap | noxcap | &oxcap |
275: smcap
276: | SM_xxx | SM_yyy | ... |
277: oxcap
278: | oxcap[0] | oxcap[1] | ... |
279: oxcap[i]
280: | ox | ncap | &cap |
281: cap
282: | CMO_xxx | CMO_yyy | ... |
283: */
284:
285: void mclist_to_mc(LIST mclist,struct mathcap *mc)
286: {
1.12 noro 287: int l,i,j;
288: NODE n,t,oxcmo,cap;
1.1 noro 289: int *ptr;
290:
291: /*
292: [
293: [ version,servername ]
294: [sm1,sm2,...],
295: [
296: [o1,[n11,n12,...]],
297: [o2,[n21,n22,...]],
298: ...
299: ]
300: ]
301: */
302: n = BDY(mclist);
303: mc->mc = mclist;
304: mc->version = BDY((USINT)BDY(BDY((LIST)BDY(n))));
305: mc->servername = BDY((STRING)BDY(NEXT(BDY((LIST)BDY(n)))));
306:
307: /* smcap */
308: n = NEXT(n);
309: t = BDY((LIST)BDY(n));
310: mc->nsmcap = length(t);
311: mc->smcap = (int *)MALLOC_ATOMIC(mc->nsmcap*sizeof(int));
312: for ( j = 0, ptr = mc->smcap; j < mc->nsmcap; j++, t = NEXT(t) )
313: ptr[j] = BDY((USINT)BDY(t));
314:
315: n = NEXT(n);
316: n = BDY((LIST)BDY(n));
317: /* n -> BDY([[OX1,CMOlist1], [OX2,CMOlist2], ...]) */
318: mc->noxcap = length(n);
319: mc->oxcap = (struct oxcap *)MALLOC(mc->noxcap*sizeof(struct oxcap));
320: for ( j = 0; j < mc->noxcap; j++, n = NEXT(n) ) {
321: oxcmo = BDY((LIST)BDY(n));
322: /* oxcmo = BDY([OXj,CMOlistj]) */
323: mc->oxcap[j].ox = BDY((USINT)BDY(oxcmo));
324: cap = BDY((LIST)BDY(NEXT(oxcmo)));
325: /* cap ->BDY(CMOlistj) */
326: l = length(cap);
327: mc->oxcap[j].ncap = l;
328: mc->oxcap[j].cap = (unsigned int *)CALLOC(l+1,sizeof(unsigned int));
329: for ( t = cap, ptr = mc->oxcap[j].cap, i = 0; i < l; t = NEXT(t), i++ )
330: ptr[i] = BDY((USINT)BDY(t));
331: }
332: }
333:
1.12 noro 334: int check_sm_by_mc(int s,unsigned int smtag)
1.1 noro 335: {
336: struct mathcap *rmc;
337: int nsmcap,i;
338: unsigned int *smcap;
339:
340: /* XXX : return 1 if remote_mc is not available. */
341: if ( !remote_mc )
342: return 1;
343: rmc = &remote_mc[s];
344: nsmcap = rmc->nsmcap;
345: smcap = rmc->smcap;
346: if ( !smcap )
347: return 1;
348: for ( i = 0; i < nsmcap; i++ )
349: if ( smcap[i] == smtag )
350: break;
351: if ( i == nsmcap )
352: return 0;
353: else
354: return 1;
355: }
356:
1.12 noro 357: int check_by_mc(int s,unsigned int oxtag,unsigned int cmotag)
1.1 noro 358: {
359: struct mathcap *rmc;
360: int noxcap,ncap,i,j;
361: struct oxcap *oxcap;
362: unsigned int *cap;
363:
364: /* XXX : return 1 if remote_mc is not available. */
365: if ( !remote_mc )
366: return 1;
367: rmc = &remote_mc[s];
368: noxcap = rmc->noxcap;
369: oxcap = rmc->oxcap;
370: if ( !oxcap )
371: return 1;
372: for ( i = 0; i < noxcap; i++ )
373: if ( oxcap[i].ox == oxtag )
374: break;
375: if ( i == noxcap )
376: return 0;
377: ncap = oxcap[i].ncap;
378: cap = oxcap[i].cap;
379: for ( j = 0; j < ncap; j++ )
380: if ( cap[j] == cmotag )
381: break;
382: if ( j == ncap )
383: return 0;
384: else
385: return 1;
386: }
387:
388: void begin_critical() {
389: critical_when_signal = 1;
390: }
391:
392: void end_critical() {
393: critical_when_signal = 0;
394: if ( ox_usr1_sent ) {
1.12 noro 395: ox_usr1_sent = 0;
396: #if !defined(VISUAL)
397: ox_usr1_handler(SIGUSR1);
398: #else
399: ox_usr1_handler(0);
400: #endif
1.1 noro 401: }
402: if ( ox_int_received ) {
403: ox_int_received = 0; int_handler(SIGINT);
404: }
405: }
406:
1.26 noro 407: extern NODE user_int_handler;
1.18 noro 408:
1.12 noro 409: void ox_usr1_handler(int sig)
1.1 noro 410: {
1.26 noro 411: NODE t;
412:
1.1 noro 413: #if !defined(VISUAL)
414: signal(SIGUSR1,ox_usr1_handler);
415: #endif
416: if ( critical_when_signal ) {
417: fprintf(stderr,"usr1 : critical\n");
418: ox_usr1_sent = 1;
419: } else {
420: ox_flushing = 1;
1.26 noro 421: if ( user_int_handler ) {
1.18 noro 422: fprintf(stderr,
1.26 noro 423: "usr1 : calling the registered exception handlers...");
424: for ( t = user_int_handler; t; t = NEXT(t) )
425: bevalf((FUNC)BDY(t),0);
1.18 noro 426: fprintf(stderr, "done.\n");
427: }
1.1 noro 428: ox_resetenv("usr1 : return to toplevel by SIGUSR1");
429: }
430: }
431:
432: void clear_readbuffer()
433: {
434: #if defined(linux)
435: iofp[0].in->_IO_read_ptr = iofp[0].in->_IO_read_end;
436: #elif defined(__FreeBSD__)
437: fpurge(iofp[0].in);
438: #endif
439: /*
440: sock = fileno(iofp[0].in);
441: interval.tv_sec = (int)0;
442: interval.tv_usec = (int)0;
443:
444: FD_ZERO(&r); FD_ZERO(&w); FD_ZERO(&e);
445: FD_SET(sock,&r);
446: while ( 1 ) {
447: n = select(FD_SETSIZE,&r,&w,&e,&interval);
448: if ( !n )
449: break;
450: read(sock,&c,1);
451: }
452: */
453: }
454:
1.20 noro 455: #if MPI
1.1 noro 456: int ox_data_is_available(int s)
457: {
458: return 1;
459: }
460:
461: void wait_for_data(int s)
462: {
463: return;
464: }
1.28 ohara 465:
466: void wait_for_data_102(int rank)
467: {
468: return;
469: }
1.1 noro 470: #else
471: int ox_data_is_available(int s)
472: {
473: return FP_DATA_IS_AVAILABLE(iofp[s].in);
474: }
475:
476: void wait_for_data(int s)
477: {
478: fd_set r;
479: int sock;
480:
481: if ( !FP_DATA_IS_AVAILABLE(iofp[s].in) ) {
482: #if defined(VISUAL)
483: sock = iofp[s].in->fildes;
484: FD_ZERO(&r);
1.12 noro 485: FD_SET((unsigned int)sock,&r);
1.1 noro 486: select(0,&r,NULL,NULL,NULL);
487: #else
488: sock = fileno(iofp[s].in);
489: FD_ZERO(&r);
490: FD_SET(sock,&r);
491: select(FD_SETSIZE,&r,NULL,NULL,NULL);
492: #endif
493: }
494: }
1.21 noro 495:
496: void wait_for_data_102(int rank)
497: {
498: fd_set r;
499: int sock;
500:
501: if ( !FP_DATA_IS_AVAILABLE(iofp_102[rank].in) ) {
502: #if defined(VISUAL)
503: sock = iofp_102[rank].in->fildes;
504: FD_ZERO(&r);
505: FD_SET((unsigned int)sock,&r);
506: select(0,&r,NULL,NULL,NULL);
507: #else
508: sock = fileno(iofp_102[rank].in);
509: FD_ZERO(&r);
510: FD_SET(sock,&r);
511: select(FD_SETSIZE,&r,NULL,NULL,NULL);
512: #endif
513: }
514: }
1.1 noro 515: #endif
516:
517: void ox_send_data(int s,pointer p)
518: {
1.8 noro 519: ERR err;
520:
521: if ( ox_check && !ox_check_cmo(s,(Obj)p) ) {
1.27 noro 522: create_error(&err,ox_serial,"ox_send_data : Mathcap violation",0);
1.8 noro 523: p = (pointer)err;
524: }
1.1 noro 525: begin_critical();
526: ox_write_int(s,OX_DATA);
527: ox_write_int(s,ox_serial++);
528: ox_write_cmo(s,p);
529: ox_flush_stream(s);
530: end_critical();
531: }
532:
1.21 noro 533: void ox_send_data_102(int rank,pointer p)
534: {
535: ERR err;
536:
537: begin_critical();
538: ox_write_int_102(rank,OX_DATA);
539: ox_write_int_102(rank,ox_serial++);
540: ox_write_cmo_102(rank,p);
541: ox_flush_stream_102(rank);
542: end_critical();
1.22 noro 543: }
544:
1.24 noro 545: void ox_bcast_102(int root)
1.22 noro 546: {
547: Obj data;
1.23 noro 548: int r,mask,id,src,dst;
1.22 noro 549:
1.23 noro 550: r = myrank_102-root;
1.24 noro 551: if ( r == 0 )
552: data = (Obj)asir_pop_one();
553:
1.23 noro 554: if ( r < 0 ) r += nserver_102;
555: for ( mask = 1; mask < nserver_102; mask <<= 1 )
1.22 noro 556: if ( r&mask ) {
1.23 noro 557: src = myrank_102-mask;
558: if ( src < 0 ) src += nserver_102;
1.22 noro 559: ox_recv_102(src,&id,&data);
560: break;
561: }
562: for ( mask >>= 1; mask > 0; mask >>= 1 )
1.23 noro 563: if ( (r+mask) < nserver_102 ) {
564: dst = myrank_102+mask;
565: if ( dst >= nserver_102 ) dst -= nserver_102;
1.22 noro 566: ox_send_data_102(dst,data);
567: }
1.24 noro 568: asir_push_one(data);
1.23 noro 569: }
570:
571: /* func : an arithmetic funcion func(vl,a,b,*c) */
572:
1.24 noro 573: void ox_reduce_102(int root,void (*func)())
1.23 noro 574: {
1.24 noro 575: Obj data,data0,t;
1.23 noro 576: int r,mask,id,src,dst;
577:
578: r = myrank_102-root;
579: if ( r < 0 ) r += nserver_102;
1.24 noro 580: data = (Obj)asir_pop_one();
1.23 noro 581: for ( mask = 1; mask < nserver_102; mask <<= 1 )
582: if ( r&mask ) {
583: dst = (r-mask)+root;
584: if ( dst >= nserver_102 ) dst -= nserver_102;
585: ox_send_data_102(dst,data);
586: break;
587: } else {
588: src = r+mask;
589: if ( src < nserver_102 ) {
590: src += root;
591: if ( src >= nserver_102 ) src -= nserver_102;
592: ox_recv_102(src,&id,&data0);
593: (*func)(CO,data,data0,&t); data = t;
594: }
595: }
1.24 noro 596: asir_push_one(r?0:data);
1.21 noro 597: }
598:
1.1 noro 599: void ox_send_cmd(int s,int id)
600: {
601: if ( ox_check && !check_sm_by_mc(s,id) )
602: error("ox_send_cmd : Mathcap violation");
603: begin_critical();
604: ox_write_int(s,OX_COMMAND);
605: ox_write_int(s,ox_serial++);
606: ox_write_int(s,id);
607: ox_flush_stream(s);
608: end_critical();
609: }
610:
611: void ox_send_sync(int s)
612: {
613: begin_critical();
614: ox_write_int(s,OX_SYNC_BALL);
615: ox_write_int(s,ox_serial++);
616: ox_flush_stream(s);
617: end_critical();
618: }
619:
1.21 noro 620: void ox_send_sync_102(int rank)
621: {
622: begin_critical();
623: ox_write_int_102(rank,OX_SYNC_BALL);
624: ox_write_int_102(rank,ox_serial++);
625: ox_flush_stream_102(rank);
626: end_critical();
627: }
628:
1.1 noro 629: void ox_send_local_data(int s,Obj p)
630: {
631: begin_critical();
632: ox_write_int(s,OX_LOCAL_OBJECT_ASIR);
633: ox_write_int(s,ox_serial++);
634: ox_write_int(s,ASIR_OBJ);
1.12 noro 635: saveobj((FILE *)iofp[s].out,p);
1.1 noro 636: ox_flush_stream(s);
637: end_critical();
638: }
639:
1.21 noro 640: void ox_send_local_data_102(int rank,Obj p)
641: {
642: begin_critical();
643: ox_write_int_102(rank,OX_LOCAL_OBJECT_ASIR);
644: ox_write_int_102(rank,ox_serial++);
645: ox_write_int_102(rank,ASIR_OBJ);
646: saveobj((FILE *)iofp_102[rank].out,p);
647: ox_flush_stream_102(rank);
648: end_critical();
649: }
650:
1.1 noro 651: void ox_send_local_ring(int s,VL vl)
652: {
653: begin_critical();
654: ox_write_int(s,OX_LOCAL_OBJECT_ASIR);
655: ox_write_int(s,ox_serial++);
656: ox_write_int(s,ASIR_VL);
1.12 noro 657: savevl((FILE *)iofp[s].out,vl);
1.1 noro 658: ox_flush_stream(s);
659: end_critical();
660: }
661:
1.21 noro 662: void ox_send_local_ring_102(int rank,VL vl)
663: {
664: begin_critical();
665: ox_write_int_102(rank,OX_LOCAL_OBJECT_ASIR);
666: ox_write_int_102(rank,ox_serial++);
667: ox_write_int_102(rank,ASIR_VL);
668: savevl((FILE *)iofp_102[rank].out,vl);
669: ox_flush_stream_102(rank);
670: end_critical();
671: }
672:
1.12 noro 673: unsigned int ox_recv(int s, int *id, Obj *p)
1.1 noro 674: {
675: unsigned int cmd,serial;
676: USINT ui;
677:
678: wait_for_data(s);
679: begin_critical();
680: ox_read_int(s,id);
681: ox_read_int(s,&serial);
682: switch ( *id ) {
683: case OX_COMMAND:
684: ox_read_int(s,&cmd);
685: MKUSINT(ui,cmd);
1.12 noro 686: *p = (Obj)ui;
1.1 noro 687: break;
688: case OX_DATA:
689: ox_read_cmo(s,p);
690: break;
691: case OX_LOCAL_OBJECT_ASIR:
692: ox_read_local(s,p);
693: break;
694: default:
695: *p = 0;
696: break;
697: }
698: end_critical();
699: return serial;
700: }
701:
1.21 noro 702: unsigned int ox_recv_102(int rank, int *id, Obj *p)
703: {
704: unsigned int cmd,serial;
705: USINT ui;
706:
707: wait_for_data_102(rank);
708: begin_critical();
709: ox_read_int_102(rank,id);
710: ox_read_int_102(rank,&serial);
711: switch ( *id ) {
712: case OX_COMMAND:
713: ox_read_int_102(rank,&cmd);
714: MKUSINT(ui,cmd);
715: *p = (Obj)ui;
716: break;
717: case OX_DATA:
718: ox_read_cmo_102(rank,p);
719: break;
720: case OX_LOCAL_OBJECT_ASIR:
721: ox_read_local_102(rank,p);
722: break;
723: default:
724: *p = 0;
725: break;
726: }
727: end_critical();
728: return serial;
729: }
730:
1.12 noro 731: void ox_get_result(int s,Obj *rp)
1.1 noro 732: {
733: int id;
734: Obj obj,r;
735: int level;
736:
737: level = 0;
738: r = 0;
739: do {
1.12 noro 740: ox_recv(s,&id,&obj);
1.1 noro 741: if ( id == OX_COMMAND ) {
742: switch ( ((USINT)obj)->body ) {
743: case SM_beginBlock:
744: level++;
745: break;
746: case SM_endBlock:
747: level--;
748: }
749: } else
750: r = obj;
751: } while ( level );
752: *rp = r;
753: }
754:
755: void ox_read_int(int s, int *n)
756: {
757: ox_need_conv = iofp[s].conv;
1.12 noro 758: read_int((FILE *)iofp[s].in,n);
1.1 noro 759: }
760:
1.21 noro 761: void ox_read_int_102(int rank, int *n)
762: {
763: ox_need_conv = iofp_102[rank].conv;
764: read_int((FILE *)iofp_102[rank].in,n);
765: }
766:
1.1 noro 767: void ox_read_cmo(int s, Obj *rp)
768: {
769: ox_need_conv = iofp[s].conv;
1.12 noro 770: read_cmo((FILE *)iofp[s].in,rp);
1.1 noro 771: }
772:
1.21 noro 773: void ox_read_cmo_102(int rank, Obj *rp)
774: {
775: ox_need_conv = iofp_102[rank].conv;
776: read_cmo((FILE *)iofp_102[rank].in,rp);
777: }
778:
779:
1.1 noro 780: void ox_read_local(int s, Obj *rp)
781: {
782: int id;
783:
784: ox_need_conv = iofp[s].conv;
1.12 noro 785: read_int((FILE *)iofp[s].in,&id);
1.1 noro 786: switch ( id ) {
787: case ASIR_VL:
1.12 noro 788: loadvl((FILE *)iofp[s].in);
1.1 noro 789: *rp = VOIDobj;
790: break;
791: case ASIR_OBJ:
1.12 noro 792: loadobj((FILE *)iofp[s].in,rp);
1.1 noro 793: break;
794: default:
795: error("ox_read_local : unsupported id");
796: break;
797: }
798: }
799:
1.21 noro 800: void ox_read_local_102(int rank, Obj *rp)
801: {
802: int id;
803:
804: ox_need_conv = iofp_102[rank].conv;
805: read_int((FILE *)iofp_102[rank].in,&id);
806: switch ( id ) {
807: case ASIR_VL:
808: loadvl((FILE *)iofp_102[rank].in);
809: *rp = VOIDobj;
810: break;
811: case ASIR_OBJ:
812: loadobj((FILE *)iofp_102[rank].in,rp);
813: break;
814: default:
815: error("ox_read_local_102 : unsupported id");
816: break;
817: }
818: }
819:
1.1 noro 820: void ox_write_int(int s, int n)
821: {
822: ox_need_conv = iofp[s].conv;
1.12 noro 823: write_int((FILE *)iofp[s].out,&n);
1.1 noro 824: }
825:
1.21 noro 826: void ox_write_int_102(int rank, int n)
827: {
828: ox_need_conv = iofp_102[rank].conv;
829: write_int((FILE *)iofp_102[rank].out,&n);
830: }
831:
1.1 noro 832: void ox_write_cmo(int s, Obj obj)
833: {
834: ox_need_conv = iofp[s].conv;
1.12 noro 835: write_cmo((FILE *)iofp[s].out,obj);
1.1 noro 836: }
837:
1.21 noro 838: void ox_write_cmo_102(int rank, Obj obj)
839: {
840: ox_need_conv = iofp_102[rank].conv;
841: write_cmo((FILE *)iofp_102[rank].out,obj);
842: }
843:
1.1 noro 844: int ox_check_cmo(int s, Obj obj)
845: {
846: NODE m;
847:
848: if ( !obj )
849: return 1;
850: switch ( OID(obj) ) {
851: case O_MATHCAP: case O_STR: case O_ERR: case O_USINT: case O_VOID:
1.10 noro 852: case O_BYTEARRAY:
1.1 noro 853: return 1;
854: case O_P:
855: if ( !check_by_mc(s,OX_DATA,CMO_RECURSIVE_POLYNOMIAL) )
856: return 0;
857: else
858: return ox_check_cmo_p(s,(P)obj);
859: case O_R:
860: if ( !check_by_mc(s,OX_DATA,CMO_RATIONAL) )
861: return 0;
862: else if ( !check_by_mc(s,OX_DATA,CMO_RECURSIVE_POLYNOMIAL) )
863: return 0;
864: else
865: return ox_check_cmo_p(s,NM((R)obj)) && ox_check_cmo_p(s,DN((R)obj));
866: case O_DP:
867: return ox_check_cmo_dp(s,(DP)obj);
868: case O_N:
1.4 noro 869: switch ( NID((Num)obj) ) {
870: case N_Q:
871: if ( INT((Q)obj) )
872: return check_by_mc(s,OX_DATA,CMO_ZZ);
873: else
874: return check_by_mc(s,OX_DATA,CMO_QQ);
875: case N_R:
876: return 1;
877: default:
878: return 0;
879: }
880: break;
1.1 noro 881: case O_LIST:
882: for ( m = BDY((LIST)obj); m; m = NEXT(m) )
883: if ( !ox_check_cmo(s,(BDY(m))) )
884: return 0;
1.11 noro 885: return 1;
886: case O_QUOTE: /* XXX */
1.1 noro 887: return 1;
888: default:
889: return 0;
890: }
891: }
892:
893: void ox_get_serverinfo(int s, LIST *rp)
894: {
895: if ( remote_mc )
896: *rp = remote_mc[s].mc;
897: else {
898: MKLIST(*rp,0);
899: }
900: }
1.15 noro 901:
902: char *ox_get_servername(int s)
903: {
904: return (remote_mc && remote_mc[s].servername)?remote_mc[s].servername:0;
905: }
906:
1.1 noro 907:
908: int ox_check_cmo_p(int s, P p)
909: {
910: DCP dc;
911:
912: if ( NUM(p) )
913: return ox_check_cmo(s,(Obj)p);
914: else {
915: for ( dc = DC(p); dc; dc = NEXT(dc) )
916: if ( !ox_check_cmo_p(s,COEF(dc)) )
917: return 0;
918: return 1;
919: }
920: }
921:
922: int ox_check_cmo_dp(int s, DP p)
923: {
924: MP m;
925:
926: for ( m = BDY(p); m; m = NEXT(m) )
927: if ( !ox_check_cmo(s,(Obj)m->c) )
928: return 0;
929: return 1;
930: }
931:
1.12 noro 932: void ox_flush_stream(int s)
1.1 noro 933: {
934: if ( ox_batch )
935: return;
936: #if defined(VISUAL)
937: if ( _fileno(&iofp[s].out->fp) < 0 )
938: cflush(iofp[s].out);
939: else
1.20 noro 940: #elif MPI
1.1 noro 941: if ( (char)fileno(&iofp[s].out->fp) < 0 )
942: cflush(iofp[s].out);
943: else
944: #endif
1.12 noro 945: fflush((FILE *)iofp[s].out);
1.1 noro 946: }
947:
1.12 noro 948: void ox_flush_stream_force(int s)
1.1 noro 949: {
950: #if defined(VISUAL)
951: if ( _fileno(&iofp[s].out->fp) < 0 )
952: cflush(iofp[s].out);
953: else
1.20 noro 954: #elif MPI
1.1 noro 955: if ( (char)fileno(&iofp[s].out->fp) < 0 )
956: cflush(iofp[s].out);
957: else
958: #endif
1.12 noro 959: fflush((FILE *)iofp[s].out);
1.21 noro 960: }
961:
962: void ox_flush_stream_102(int rank)
963: {
964: if ( !ox_batch )
965: ox_flush_stream_force_102(rank);
966: }
967:
968: void ox_flush_stream_force_102(int rank)
969: {
970: if ( iofp_102[rank].out )
971: #if defined(VISUAL)
972: cflush(iofp_102[rank].out);
973: #elif MPI
974: cflush(iofp_102[rank].out);
975: #else
976: fflush(iofp_102[rank].out);
977: #endif
1.1 noro 978: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>