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