=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/io/ox.c,v retrieving revision 1.6 retrieving revision 1.22 diff -u -p -r1.6 -r1.22 --- OpenXM_contrib2/asir2000/io/ox.c 2000/08/22 05:04:18 1.6 +++ OpenXM_contrib2/asir2000/io/ox.c 2003/12/10 05:39:58 1.22 @@ -44,7 +44,7 @@ * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. - * $OpenXM: OpenXM_contrib2/asir2000/io/ox.c,v 1.5 2000/08/21 08:31:38 noro Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/io/ox.c,v 1.21 2003/12/09 03:07:45 noro Exp $ */ #include "ca.h" #include "parse.h" @@ -54,21 +54,17 @@ #define ISIZ sizeof(int) -void ox_flush_stream(),ox_write_int(),ox_write_cmo(); -void ox_read_int(),ox_read_cmo(); -void mclist_to_mc(); -void ox_read_local(); - extern Obj VOIDobj; +extern int nserver_102, myrank_102; extern int ox_need_conv; -extern int ox_usr1_sent, ox_int_received, critical_when_signal; +int ox_usr1_sent, ox_int_received, critical_when_signal; unsigned int ox_serial; int ox_flushing; int ox_batch; int ox_check=1; int ox_exchange_mathcap=1; -jmp_buf ox_env; +JMP_BUF ox_env; MATHCAP my_mathcap; @@ -94,11 +90,28 @@ static struct mathcap my_mc; static struct mathcap *remote_mc; static int remote_mc_len; -void ox_resetenv(s) -char *s; +void mclist_to_mc(LIST mclist,struct mathcap *mc); + +#if defined(VISUAL) +/* XXX : mainly used in engine2000/io.c, but declared here */ +HANDLE hStreamNotify,hStreamNotify_Ack; + +void cleanup_events() { + /* ox_watch_stream may be waiting for hStreamNotify_Ack to be set */ + + ResetEvent(hStreamNotify); + SetEvent(hStreamNotify_Ack); +} +#endif + +void ox_resetenv(char *s) +{ +#if defined(VISUAL) + cleanup_events(); +#endif fprintf(stderr,"%s\n",s); - longjmp(ox_env,1); + LONGJMP(ox_env,1); } static int available_cmo[] = { @@ -109,12 +122,13 @@ static int available_cmo[] = { CMO_RING_BY_NAME, CMO_DISTRIBUTED_POLYNOMIAL, CMO_RECURSIVE_POLYNOMIAL, CMO_UNIVARIATE_POLYNOMIAL, CMO_INDETERMINATE, + CMO_TREE, 0 }; -static int available_sm[] = { +static int asir_available_sm[] = { SM_dupErrors, SM_getsp, SM_popSerializedLocalObject, - SM_popCMO, SM_popString, SM_setName, + SM_popCMO, SM_popString, SM_pushCMOtag, SM_setName, SM_evalName, SM_executeStringByLocalParser, SM_executeStringByLocalParserInBatchMode, SM_executeFunction, SM_shutdown, SM_pops, @@ -123,6 +137,27 @@ static int available_sm[] = { 0 }; +static int ox_asir_available_sm[] = { + SM_dupErrors, SM_getsp, SM_popSerializedLocalObject, + SM_popCMO, SM_popString, SM_pushCMOtag, SM_setName, + SM_evalName, SM_executeStringByLocalParser, + SM_executeStringByLocalParserInBatchMode, + SM_executeFunction, SM_shutdown, SM_pops, + SM_mathcap, SM_setMathcap, SM_nop, + SM_beginBlock, SM_endBlock, + SM_set_rank_102, SM_tcp_accept_102, SM_tcp_connect_102, SM_reset_102, + 0 +}; + +static int ox_plot_available_sm[] = { + SM_dupErrors, SM_getsp, SM_popSerializedLocalObject, + SM_popCMO, SM_popString, SM_setName, + SM_evalName, SM_executeStringByLocalParser, + SM_executeFunction, SM_shutdown, SM_pops, + SM_mathcap, SM_setMathcap, SM_nop, + 0 +}; + /* mathcap = [ @@ -141,7 +176,7 @@ void create_my_mathcap(char *system) NODE n,n0; int i,k; STRING str; - LIST sname,smlist,oxlist,cmolist,asirlist,oxtag,oxasir,r; + LIST sname,smlist,oxlist,cmolist,asirlist,oxasir,r; USINT tag,t,t1; if ( my_mathcap ) @@ -151,11 +186,24 @@ void create_my_mathcap(char *system) MKUSINT(t,OX_VERSION); n0 = mknode(2,t,str); MKLIST(sname,n0); - /* cmo tag */ - for ( n0 = 0, i = 0; k = available_sm[i]; i++ ) { - NEXTNODE(n0,n); MKUSINT(t,k); BDY(n) = (pointer)t; + /* sm tag */ + n0 = 0; + if ( !strcmp(system,"asir") ) { + for ( i = 0; k = asir_available_sm[i]; i++ ) { + NEXTNODE(n0,n); MKUSINT(t,k); BDY(n) = (pointer)t; + } + } else if ( !strcmp(system,"ox_asir") ) { + for ( i = 0; k = ox_asir_available_sm[i]; i++ ) { + NEXTNODE(n0,n); MKUSINT(t,k); BDY(n) = (pointer)t; + } + NEXT(n) = 0; + } else if ( !strcmp(system,"ox_plot") ) { + for ( i = 0; k = ox_plot_available_sm[i]; i++ ) { + NEXTNODE(n0,n); MKUSINT(t,k); BDY(n) = (pointer)t; + } + NEXT(n) = 0; } - NEXT(n) = 0; MKLIST(smlist,n0); + MKLIST(smlist,n0); /* creation of [OX_DATA,CMO list] */ /* ox tag */ @@ -234,8 +282,8 @@ void store_remote_mathcap(int s,MATHCAP mc) void mclist_to_mc(LIST mclist,struct mathcap *mc) { - int id,l,i,j; - NODE n,t,oxcmo,ox,cap; + int l,i,j; + NODE n,t,oxcmo,cap; int *ptr; /* @@ -281,9 +329,7 @@ void mclist_to_mc(LIST mclist,struct mathcap *mc) } } -int check_sm_by_mc(s,smtag) -int s; -unsigned int smtag; +int check_sm_by_mc(int s,unsigned int smtag) { struct mathcap *rmc; int nsmcap,i; @@ -306,9 +352,7 @@ unsigned int smtag; return 1; } -int check_by_mc(s,oxtag,cmotag) -int s; -unsigned int oxtag,cmotag; +int check_by_mc(int s,unsigned int oxtag,unsigned int cmotag) { struct mathcap *rmc; int noxcap,ncap,i,j; @@ -346,19 +390,22 @@ void begin_critical() { void end_critical() { critical_when_signal = 0; if ( ox_usr1_sent ) { - ox_usr1_sent = 0; ox_usr1_handler(); + ox_usr1_sent = 0; +#if !defined(VISUAL) + ox_usr1_handler(SIGUSR1); +#else + ox_usr1_handler(0); +#endif } if ( ox_int_received ) { ox_int_received = 0; int_handler(SIGINT); } } -void ox_usr1_handler(sig) -int sig; -{ - extern jmp_buf env; - unsigned int cmd; +extern FUNC registered_handler; +void ox_usr1_handler(int sig) +{ #if !defined(VISUAL) signal(SIGUSR1,ox_usr1_handler); #endif @@ -367,17 +414,18 @@ int sig; ox_usr1_sent = 1; } else { ox_flushing = 1; + if ( registered_handler ) { + fprintf(stderr, + "usr1 : calling the registered exception handler..."); + bevalf(registered_handler,0); + fprintf(stderr, "done.\n"); + } ox_resetenv("usr1 : return to toplevel by SIGUSR1"); } } void clear_readbuffer() { - char c; - fd_set r,w,e; - struct timeval interval; - int n,sock; - #if defined(linux) iofp[0].in->_IO_read_ptr = iofp[0].in->_IO_read_end; #elif defined(__FreeBSD__) @@ -424,7 +472,7 @@ void wait_for_data(int s) #if defined(VISUAL) sock = iofp[s].in->fildes; FD_ZERO(&r); - FD_SET(sock,&r); + FD_SET((unsigned int)sock,&r); select(0,&r,NULL,NULL,NULL); #else sock = fileno(iofp[s].in); @@ -434,12 +482,36 @@ void wait_for_data(int s) #endif } } + +void wait_for_data_102(int rank) +{ + fd_set r; + int sock; + + if ( !FP_DATA_IS_AVAILABLE(iofp_102[rank].in) ) { +#if defined(VISUAL) + sock = iofp_102[rank].in->fildes; + FD_ZERO(&r); + FD_SET((unsigned int)sock,&r); + select(0,&r,NULL,NULL,NULL); +#else + sock = fileno(iofp_102[rank].in); + FD_ZERO(&r); + FD_SET(sock,&r); + select(FD_SETSIZE,&r,NULL,NULL,NULL); #endif + } +} +#endif void ox_send_data(int s,pointer p) { - if ( ox_check && !ox_check_cmo(s,(Obj)p) ) - error("ox_send_data : Mathcap violation"); + ERR err; + + if ( ox_check && !ox_check_cmo(s,(Obj)p) ) { + create_error(&err,ox_serial,"ox_send_data : Mathcap violation"); + p = (pointer)err; + } begin_critical(); ox_write_int(s,OX_DATA); ox_write_int(s,ox_serial++); @@ -448,6 +520,44 @@ void ox_send_data(int s,pointer p) end_critical(); } +void ox_send_data_102(int rank,pointer p) +{ + ERR err; + + begin_critical(); + ox_write_int_102(rank,OX_DATA); + ox_write_int_102(rank,ox_serial++); + ox_write_cmo_102(rank,p); + ox_flush_stream_102(rank); + end_critical(); +} + +void ox_bcast_102(int root,Obj *rp) +{ + Obj data; + int n,myr,r,mask,src,dst,id; + + data = *rp; + n = nserver_102; + myr = myrank_102; + r = myr-root; + if ( r < 0 ) r += n; + for ( mask = 1; mask < n; mask <<= 1 ) + if ( r&mask ) { + src = myr-mask; + if ( src < 0 ) src += n; + ox_recv_102(src,&id,&data); + break; + } + for ( mask >>= 1; mask > 0; mask >>= 1 ) + if ( (r+mask) < n ) { + dst = myr+mask; + if ( dst >= n ) dst -= n; + ox_send_data_102(dst,data); + } + *rp = data; +} + void ox_send_cmd(int s,int id) { if ( ox_check && !check_sm_by_mc(s,id) ) @@ -469,30 +579,61 @@ void ox_send_sync(int s) end_critical(); } +void ox_send_sync_102(int rank) +{ + begin_critical(); + ox_write_int_102(rank,OX_SYNC_BALL); + ox_write_int_102(rank,ox_serial++); + ox_flush_stream_102(rank); + end_critical(); +} + void ox_send_local_data(int s,Obj p) { begin_critical(); ox_write_int(s,OX_LOCAL_OBJECT_ASIR); ox_write_int(s,ox_serial++); ox_write_int(s,ASIR_OBJ); - saveobj(iofp[s].out,p); + saveobj((FILE *)iofp[s].out,p); ox_flush_stream(s); end_critical(); } +void ox_send_local_data_102(int rank,Obj p) +{ + begin_critical(); + ox_write_int_102(rank,OX_LOCAL_OBJECT_ASIR); + ox_write_int_102(rank,ox_serial++); + ox_write_int_102(rank,ASIR_OBJ); + saveobj((FILE *)iofp_102[rank].out,p); + ox_flush_stream_102(rank); + end_critical(); +} + void ox_send_local_ring(int s,VL vl) { begin_critical(); ox_write_int(s,OX_LOCAL_OBJECT_ASIR); ox_write_int(s,ox_serial++); ox_write_int(s,ASIR_VL); - savevl(iofp[s].out,vl); + savevl((FILE *)iofp[s].out,vl); ox_flush_stream(s); end_critical(); } -unsigned int ox_recv(int s, int *id, pointer *p) +void ox_send_local_ring_102(int rank,VL vl) { + begin_critical(); + ox_write_int_102(rank,OX_LOCAL_OBJECT_ASIR); + ox_write_int_102(rank,ox_serial++); + ox_write_int_102(rank,ASIR_VL); + savevl((FILE *)iofp_102[rank].out,vl); + ox_flush_stream_102(rank); + end_critical(); +} + +unsigned int ox_recv(int s, int *id, Obj *p) +{ unsigned int cmd,serial; USINT ui; @@ -504,7 +645,7 @@ unsigned int ox_recv(int s, int *id, pointer *p) case OX_COMMAND: ox_read_int(s,&cmd); MKUSINT(ui,cmd); - *p = (pointer)ui; + *p = (Obj)ui; break; case OX_DATA: ox_read_cmo(s,p); @@ -520,10 +661,37 @@ unsigned int ox_recv(int s, int *id, pointer *p) return serial; } -void ox_get_result(s,rp) -int s; -Obj *rp; +unsigned int ox_recv_102(int rank, int *id, Obj *p) { + unsigned int cmd,serial; + USINT ui; + + wait_for_data_102(rank); + begin_critical(); + ox_read_int_102(rank,id); + ox_read_int_102(rank,&serial); + switch ( *id ) { + case OX_COMMAND: + ox_read_int_102(rank,&cmd); + MKUSINT(ui,cmd); + *p = (Obj)ui; + break; + case OX_DATA: + ox_read_cmo_102(rank,p); + break; + case OX_LOCAL_OBJECT_ASIR: + ox_read_local_102(rank,p); + break; + default: + *p = 0; + break; + } + end_critical(); + return serial; +} + +void ox_get_result(int s,Obj *rp) +{ int id; Obj obj,r; int level; @@ -531,7 +699,7 @@ Obj *rp; level = 0; r = 0; do { - ox_recv(s,&id,(pointer *)&obj); + ox_recv(s,&id,&obj); if ( id == OX_COMMAND ) { switch ( ((USINT)obj)->body ) { case SM_beginBlock: @@ -549,28 +717,41 @@ Obj *rp; void ox_read_int(int s, int *n) { ox_need_conv = iofp[s].conv; - read_int(iofp[s].in,n); + read_int((FILE *)iofp[s].in,n); } +void ox_read_int_102(int rank, int *n) +{ + ox_need_conv = iofp_102[rank].conv; + read_int((FILE *)iofp_102[rank].in,n); +} + void ox_read_cmo(int s, Obj *rp) { ox_need_conv = iofp[s].conv; - read_cmo(iofp[s].in,rp); + read_cmo((FILE *)iofp[s].in,rp); } +void ox_read_cmo_102(int rank, Obj *rp) +{ + ox_need_conv = iofp_102[rank].conv; + read_cmo((FILE *)iofp_102[rank].in,rp); +} + + void ox_read_local(int s, Obj *rp) { int id; ox_need_conv = iofp[s].conv; - read_int(iofp[s].in,&id); + read_int((FILE *)iofp[s].in,&id); switch ( id ) { case ASIR_VL: - loadvl(iofp[s].in); + loadvl((FILE *)iofp[s].in); *rp = VOIDobj; break; case ASIR_OBJ: - loadobj(iofp[s].in,rp); + loadobj((FILE *)iofp[s].in,rp); break; default: error("ox_read_local : unsupported id"); @@ -578,18 +759,50 @@ void ox_read_local(int s, Obj *rp) } } +void ox_read_local_102(int rank, Obj *rp) +{ + int id; + + ox_need_conv = iofp_102[rank].conv; + read_int((FILE *)iofp_102[rank].in,&id); + switch ( id ) { + case ASIR_VL: + loadvl((FILE *)iofp_102[rank].in); + *rp = VOIDobj; + break; + case ASIR_OBJ: + loadobj((FILE *)iofp_102[rank].in,rp); + break; + default: + error("ox_read_local_102 : unsupported id"); + break; + } +} + void ox_write_int(int s, int n) { ox_need_conv = iofp[s].conv; - write_int(iofp[s].out,&n); + write_int((FILE *)iofp[s].out,&n); } +void ox_write_int_102(int rank, int n) +{ + ox_need_conv = iofp_102[rank].conv; + write_int((FILE *)iofp_102[rank].out,&n); +} + void ox_write_cmo(int s, Obj obj) { ox_need_conv = iofp[s].conv; - write_cmo(iofp[s].out,obj); + write_cmo((FILE *)iofp[s].out,obj); } +void ox_write_cmo_102(int rank, Obj obj) +{ + ox_need_conv = iofp_102[rank].conv; + write_cmo((FILE *)iofp_102[rank].out,obj); +} + int ox_check_cmo(int s, Obj obj) { NODE m; @@ -598,6 +811,7 @@ int ox_check_cmo(int s, Obj obj) return 1; switch ( OID(obj) ) { case O_MATHCAP: case O_STR: case O_ERR: case O_USINT: case O_VOID: + case O_BYTEARRAY: return 1; case O_P: if ( !check_by_mc(s,OX_DATA,CMO_RECURSIVE_POLYNOMIAL) ) @@ -631,6 +845,8 @@ int ox_check_cmo(int s, Obj obj) if ( !ox_check_cmo(s,(BDY(m))) ) return 0; return 1; + case O_QUOTE: /* XXX */ + return 1; default: return 0; } @@ -645,6 +861,12 @@ void ox_get_serverinfo(int s, LIST *rp) } } +char *ox_get_servername(int s) +{ + return (remote_mc && remote_mc[s].servername)?remote_mc[s].servername:0; +} + + int ox_check_cmo_p(int s, P p) { DCP dc; @@ -669,8 +891,7 @@ int ox_check_cmo_dp(int s, DP p) return 1; } -void ox_flush_stream(s) -int s; +void ox_flush_stream(int s) { if ( ox_batch ) return; @@ -683,11 +904,10 @@ int s; cflush(iofp[s].out); else #endif - fflush(iofp[s].out); + fflush((FILE *)iofp[s].out); } -void ox_flush_stream_force(s) -int s; +void ox_flush_stream_force(int s) { #if defined(VISUAL) if ( _fileno(&iofp[s].out->fp) < 0 ) @@ -698,5 +918,23 @@ int s; cflush(iofp[s].out); else #endif - fflush(iofp[s].out); + fflush((FILE *)iofp[s].out); +} + +void ox_flush_stream_102(int rank) +{ + if ( !ox_batch ) + ox_flush_stream_force_102(rank); +} + +void ox_flush_stream_force_102(int rank) +{ + if ( iofp_102[rank].out ) +#if defined(VISUAL) + cflush(iofp_102[rank].out); +#elif MPI + cflush(iofp_102[rank].out); +#else + fflush(iofp_102[rank].out); +#endif }