Annotation of OpenXM_contrib2/asir2000/io/ox.c, Revision 1.26
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.26 ! noro 47: * $OpenXM: OpenXM_contrib2/asir2000/io/ox.c,v 1.25 2004/08/28 12:50:30 takayama 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,
148: SM_beginBlock, SM_endBlock,
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: }
465: #else
466: int ox_data_is_available(int s)
467: {
468: return FP_DATA_IS_AVAILABLE(iofp[s].in);
469: }
470:
471: void wait_for_data(int s)
472: {
473: fd_set r;
474: int sock;
475:
476: if ( !FP_DATA_IS_AVAILABLE(iofp[s].in) ) {
477: #if defined(VISUAL)
478: sock = iofp[s].in->fildes;
479: FD_ZERO(&r);
1.12 noro 480: FD_SET((unsigned int)sock,&r);
1.1 noro 481: select(0,&r,NULL,NULL,NULL);
482: #else
483: sock = fileno(iofp[s].in);
484: FD_ZERO(&r);
485: FD_SET(sock,&r);
486: select(FD_SETSIZE,&r,NULL,NULL,NULL);
487: #endif
488: }
489: }
1.21 noro 490:
491: void wait_for_data_102(int rank)
492: {
493: fd_set r;
494: int sock;
495:
496: if ( !FP_DATA_IS_AVAILABLE(iofp_102[rank].in) ) {
497: #if defined(VISUAL)
498: sock = iofp_102[rank].in->fildes;
499: FD_ZERO(&r);
500: FD_SET((unsigned int)sock,&r);
501: select(0,&r,NULL,NULL,NULL);
502: #else
503: sock = fileno(iofp_102[rank].in);
504: FD_ZERO(&r);
505: FD_SET(sock,&r);
506: select(FD_SETSIZE,&r,NULL,NULL,NULL);
507: #endif
508: }
509: }
1.1 noro 510: #endif
511:
512: void ox_send_data(int s,pointer p)
513: {
1.8 noro 514: ERR err;
515:
516: if ( ox_check && !ox_check_cmo(s,(Obj)p) ) {
517: create_error(&err,ox_serial,"ox_send_data : Mathcap violation");
518: p = (pointer)err;
519: }
1.1 noro 520: begin_critical();
521: ox_write_int(s,OX_DATA);
522: ox_write_int(s,ox_serial++);
523: ox_write_cmo(s,p);
524: ox_flush_stream(s);
525: end_critical();
526: }
527:
1.21 noro 528: void ox_send_data_102(int rank,pointer p)
529: {
530: ERR err;
531:
532: begin_critical();
533: ox_write_int_102(rank,OX_DATA);
534: ox_write_int_102(rank,ox_serial++);
535: ox_write_cmo_102(rank,p);
536: ox_flush_stream_102(rank);
537: end_critical();
1.22 noro 538: }
539:
1.24 noro 540: void ox_bcast_102(int root)
1.22 noro 541: {
542: Obj data;
1.23 noro 543: int r,mask,id,src,dst;
1.22 noro 544:
1.23 noro 545: r = myrank_102-root;
1.24 noro 546: if ( r == 0 )
547: data = (Obj)asir_pop_one();
548:
1.23 noro 549: if ( r < 0 ) r += nserver_102;
550: for ( mask = 1; mask < nserver_102; mask <<= 1 )
1.22 noro 551: if ( r&mask ) {
1.23 noro 552: src = myrank_102-mask;
553: if ( src < 0 ) src += nserver_102;
1.22 noro 554: ox_recv_102(src,&id,&data);
555: break;
556: }
557: for ( mask >>= 1; mask > 0; mask >>= 1 )
1.23 noro 558: if ( (r+mask) < nserver_102 ) {
559: dst = myrank_102+mask;
560: if ( dst >= nserver_102 ) dst -= nserver_102;
1.22 noro 561: ox_send_data_102(dst,data);
562: }
1.24 noro 563: asir_push_one(data);
1.23 noro 564: }
565:
566: /* func : an arithmetic funcion func(vl,a,b,*c) */
567:
1.24 noro 568: void ox_reduce_102(int root,void (*func)())
1.23 noro 569: {
1.24 noro 570: Obj data,data0,t;
1.23 noro 571: int r,mask,id,src,dst;
572:
573: r = myrank_102-root;
574: if ( r < 0 ) r += nserver_102;
1.24 noro 575: data = (Obj)asir_pop_one();
1.23 noro 576: for ( mask = 1; mask < nserver_102; mask <<= 1 )
577: if ( r&mask ) {
578: dst = (r-mask)+root;
579: if ( dst >= nserver_102 ) dst -= nserver_102;
580: ox_send_data_102(dst,data);
581: break;
582: } else {
583: src = r+mask;
584: if ( src < nserver_102 ) {
585: src += root;
586: if ( src >= nserver_102 ) src -= nserver_102;
587: ox_recv_102(src,&id,&data0);
588: (*func)(CO,data,data0,&t); data = t;
589: }
590: }
1.24 noro 591: asir_push_one(r?0:data);
1.21 noro 592: }
593:
1.1 noro 594: void ox_send_cmd(int s,int id)
595: {
596: if ( ox_check && !check_sm_by_mc(s,id) )
597: error("ox_send_cmd : Mathcap violation");
598: begin_critical();
599: ox_write_int(s,OX_COMMAND);
600: ox_write_int(s,ox_serial++);
601: ox_write_int(s,id);
602: ox_flush_stream(s);
603: end_critical();
604: }
605:
606: void ox_send_sync(int s)
607: {
608: begin_critical();
609: ox_write_int(s,OX_SYNC_BALL);
610: ox_write_int(s,ox_serial++);
611: ox_flush_stream(s);
612: end_critical();
613: }
614:
1.21 noro 615: void ox_send_sync_102(int rank)
616: {
617: begin_critical();
618: ox_write_int_102(rank,OX_SYNC_BALL);
619: ox_write_int_102(rank,ox_serial++);
620: ox_flush_stream_102(rank);
621: end_critical();
622: }
623:
1.1 noro 624: void ox_send_local_data(int s,Obj p)
625: {
626: begin_critical();
627: ox_write_int(s,OX_LOCAL_OBJECT_ASIR);
628: ox_write_int(s,ox_serial++);
629: ox_write_int(s,ASIR_OBJ);
1.12 noro 630: saveobj((FILE *)iofp[s].out,p);
1.1 noro 631: ox_flush_stream(s);
632: end_critical();
633: }
634:
1.21 noro 635: void ox_send_local_data_102(int rank,Obj p)
636: {
637: begin_critical();
638: ox_write_int_102(rank,OX_LOCAL_OBJECT_ASIR);
639: ox_write_int_102(rank,ox_serial++);
640: ox_write_int_102(rank,ASIR_OBJ);
641: saveobj((FILE *)iofp_102[rank].out,p);
642: ox_flush_stream_102(rank);
643: end_critical();
644: }
645:
1.1 noro 646: void ox_send_local_ring(int s,VL vl)
647: {
648: begin_critical();
649: ox_write_int(s,OX_LOCAL_OBJECT_ASIR);
650: ox_write_int(s,ox_serial++);
651: ox_write_int(s,ASIR_VL);
1.12 noro 652: savevl((FILE *)iofp[s].out,vl);
1.1 noro 653: ox_flush_stream(s);
654: end_critical();
655: }
656:
1.21 noro 657: void ox_send_local_ring_102(int rank,VL vl)
658: {
659: begin_critical();
660: ox_write_int_102(rank,OX_LOCAL_OBJECT_ASIR);
661: ox_write_int_102(rank,ox_serial++);
662: ox_write_int_102(rank,ASIR_VL);
663: savevl((FILE *)iofp_102[rank].out,vl);
664: ox_flush_stream_102(rank);
665: end_critical();
666: }
667:
1.12 noro 668: unsigned int ox_recv(int s, int *id, Obj *p)
1.1 noro 669: {
670: unsigned int cmd,serial;
671: USINT ui;
672:
673: wait_for_data(s);
674: begin_critical();
675: ox_read_int(s,id);
676: ox_read_int(s,&serial);
677: switch ( *id ) {
678: case OX_COMMAND:
679: ox_read_int(s,&cmd);
680: MKUSINT(ui,cmd);
1.12 noro 681: *p = (Obj)ui;
1.1 noro 682: break;
683: case OX_DATA:
684: ox_read_cmo(s,p);
685: break;
686: case OX_LOCAL_OBJECT_ASIR:
687: ox_read_local(s,p);
688: break;
689: default:
690: *p = 0;
691: break;
692: }
693: end_critical();
694: return serial;
695: }
696:
1.21 noro 697: unsigned int ox_recv_102(int rank, int *id, Obj *p)
698: {
699: unsigned int cmd,serial;
700: USINT ui;
701:
702: wait_for_data_102(rank);
703: begin_critical();
704: ox_read_int_102(rank,id);
705: ox_read_int_102(rank,&serial);
706: switch ( *id ) {
707: case OX_COMMAND:
708: ox_read_int_102(rank,&cmd);
709: MKUSINT(ui,cmd);
710: *p = (Obj)ui;
711: break;
712: case OX_DATA:
713: ox_read_cmo_102(rank,p);
714: break;
715: case OX_LOCAL_OBJECT_ASIR:
716: ox_read_local_102(rank,p);
717: break;
718: default:
719: *p = 0;
720: break;
721: }
722: end_critical();
723: return serial;
724: }
725:
1.12 noro 726: void ox_get_result(int s,Obj *rp)
1.1 noro 727: {
728: int id;
729: Obj obj,r;
730: int level;
731:
732: level = 0;
733: r = 0;
734: do {
1.12 noro 735: ox_recv(s,&id,&obj);
1.1 noro 736: if ( id == OX_COMMAND ) {
737: switch ( ((USINT)obj)->body ) {
738: case SM_beginBlock:
739: level++;
740: break;
741: case SM_endBlock:
742: level--;
743: }
744: } else
745: r = obj;
746: } while ( level );
747: *rp = r;
748: }
749:
750: void ox_read_int(int s, int *n)
751: {
752: ox_need_conv = iofp[s].conv;
1.12 noro 753: read_int((FILE *)iofp[s].in,n);
1.1 noro 754: }
755:
1.21 noro 756: void ox_read_int_102(int rank, int *n)
757: {
758: ox_need_conv = iofp_102[rank].conv;
759: read_int((FILE *)iofp_102[rank].in,n);
760: }
761:
1.1 noro 762: void ox_read_cmo(int s, Obj *rp)
763: {
764: ox_need_conv = iofp[s].conv;
1.12 noro 765: read_cmo((FILE *)iofp[s].in,rp);
1.1 noro 766: }
767:
1.21 noro 768: void ox_read_cmo_102(int rank, Obj *rp)
769: {
770: ox_need_conv = iofp_102[rank].conv;
771: read_cmo((FILE *)iofp_102[rank].in,rp);
772: }
773:
774:
1.1 noro 775: void ox_read_local(int s, Obj *rp)
776: {
777: int id;
778:
779: ox_need_conv = iofp[s].conv;
1.12 noro 780: read_int((FILE *)iofp[s].in,&id);
1.1 noro 781: switch ( id ) {
782: case ASIR_VL:
1.12 noro 783: loadvl((FILE *)iofp[s].in);
1.1 noro 784: *rp = VOIDobj;
785: break;
786: case ASIR_OBJ:
1.12 noro 787: loadobj((FILE *)iofp[s].in,rp);
1.1 noro 788: break;
789: default:
790: error("ox_read_local : unsupported id");
791: break;
792: }
793: }
794:
1.21 noro 795: void ox_read_local_102(int rank, Obj *rp)
796: {
797: int id;
798:
799: ox_need_conv = iofp_102[rank].conv;
800: read_int((FILE *)iofp_102[rank].in,&id);
801: switch ( id ) {
802: case ASIR_VL:
803: loadvl((FILE *)iofp_102[rank].in);
804: *rp = VOIDobj;
805: break;
806: case ASIR_OBJ:
807: loadobj((FILE *)iofp_102[rank].in,rp);
808: break;
809: default:
810: error("ox_read_local_102 : unsupported id");
811: break;
812: }
813: }
814:
1.1 noro 815: void ox_write_int(int s, int n)
816: {
817: ox_need_conv = iofp[s].conv;
1.12 noro 818: write_int((FILE *)iofp[s].out,&n);
1.1 noro 819: }
820:
1.21 noro 821: void ox_write_int_102(int rank, int n)
822: {
823: ox_need_conv = iofp_102[rank].conv;
824: write_int((FILE *)iofp_102[rank].out,&n);
825: }
826:
1.1 noro 827: void ox_write_cmo(int s, Obj obj)
828: {
829: ox_need_conv = iofp[s].conv;
1.12 noro 830: write_cmo((FILE *)iofp[s].out,obj);
1.1 noro 831: }
832:
1.21 noro 833: void ox_write_cmo_102(int rank, Obj obj)
834: {
835: ox_need_conv = iofp_102[rank].conv;
836: write_cmo((FILE *)iofp_102[rank].out,obj);
837: }
838:
1.1 noro 839: int ox_check_cmo(int s, Obj obj)
840: {
841: NODE m;
842:
843: if ( !obj )
844: return 1;
845: switch ( OID(obj) ) {
846: case O_MATHCAP: case O_STR: case O_ERR: case O_USINT: case O_VOID:
1.10 noro 847: case O_BYTEARRAY:
1.1 noro 848: return 1;
849: case O_P:
850: if ( !check_by_mc(s,OX_DATA,CMO_RECURSIVE_POLYNOMIAL) )
851: return 0;
852: else
853: return ox_check_cmo_p(s,(P)obj);
854: case O_R:
855: if ( !check_by_mc(s,OX_DATA,CMO_RATIONAL) )
856: return 0;
857: else if ( !check_by_mc(s,OX_DATA,CMO_RECURSIVE_POLYNOMIAL) )
858: return 0;
859: else
860: return ox_check_cmo_p(s,NM((R)obj)) && ox_check_cmo_p(s,DN((R)obj));
861: case O_DP:
862: return ox_check_cmo_dp(s,(DP)obj);
863: case O_N:
1.4 noro 864: switch ( NID((Num)obj) ) {
865: case N_Q:
866: if ( INT((Q)obj) )
867: return check_by_mc(s,OX_DATA,CMO_ZZ);
868: else
869: return check_by_mc(s,OX_DATA,CMO_QQ);
870: case N_R:
871: return 1;
872: default:
873: return 0;
874: }
875: break;
1.1 noro 876: case O_LIST:
877: for ( m = BDY((LIST)obj); m; m = NEXT(m) )
878: if ( !ox_check_cmo(s,(BDY(m))) )
879: return 0;
1.11 noro 880: return 1;
881: case O_QUOTE: /* XXX */
1.1 noro 882: return 1;
883: default:
884: return 0;
885: }
886: }
887:
888: void ox_get_serverinfo(int s, LIST *rp)
889: {
890: if ( remote_mc )
891: *rp = remote_mc[s].mc;
892: else {
893: MKLIST(*rp,0);
894: }
895: }
1.15 noro 896:
897: char *ox_get_servername(int s)
898: {
899: return (remote_mc && remote_mc[s].servername)?remote_mc[s].servername:0;
900: }
901:
1.1 noro 902:
903: int ox_check_cmo_p(int s, P p)
904: {
905: DCP dc;
906:
907: if ( NUM(p) )
908: return ox_check_cmo(s,(Obj)p);
909: else {
910: for ( dc = DC(p); dc; dc = NEXT(dc) )
911: if ( !ox_check_cmo_p(s,COEF(dc)) )
912: return 0;
913: return 1;
914: }
915: }
916:
917: int ox_check_cmo_dp(int s, DP p)
918: {
919: MP m;
920:
921: for ( m = BDY(p); m; m = NEXT(m) )
922: if ( !ox_check_cmo(s,(Obj)m->c) )
923: return 0;
924: return 1;
925: }
926:
1.12 noro 927: void ox_flush_stream(int s)
1.1 noro 928: {
929: if ( ox_batch )
930: return;
931: #if defined(VISUAL)
932: if ( _fileno(&iofp[s].out->fp) < 0 )
933: cflush(iofp[s].out);
934: else
1.20 noro 935: #elif MPI
1.1 noro 936: if ( (char)fileno(&iofp[s].out->fp) < 0 )
937: cflush(iofp[s].out);
938: else
939: #endif
1.12 noro 940: fflush((FILE *)iofp[s].out);
1.1 noro 941: }
942:
1.12 noro 943: void ox_flush_stream_force(int s)
1.1 noro 944: {
945: #if defined(VISUAL)
946: if ( _fileno(&iofp[s].out->fp) < 0 )
947: cflush(iofp[s].out);
948: else
1.20 noro 949: #elif MPI
1.1 noro 950: if ( (char)fileno(&iofp[s].out->fp) < 0 )
951: cflush(iofp[s].out);
952: else
953: #endif
1.12 noro 954: fflush((FILE *)iofp[s].out);
1.21 noro 955: }
956:
957: void ox_flush_stream_102(int rank)
958: {
959: if ( !ox_batch )
960: ox_flush_stream_force_102(rank);
961: }
962:
963: void ox_flush_stream_force_102(int rank)
964: {
965: if ( iofp_102[rank].out )
966: #if defined(VISUAL)
967: cflush(iofp_102[rank].out);
968: #elif MPI
969: cflush(iofp_102[rank].out);
970: #else
971: fflush(iofp_102[rank].out);
972: #endif
1.1 noro 973: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>