version 1.15, 2002/08/02 02:28:27 |
version 1.34, 2015/08/08 14:19:42 |
|
|
* OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY |
* OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* $OpenXM: OpenXM_contrib2/asir2000/io/ox.c,v 1.14 2002/07/25 04:47:41 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/io/ox.c,v 1.33 2015/08/06 10:01:52 fujimoto Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
|
|
|
|
extern Obj VOIDobj; |
extern Obj VOIDobj; |
|
|
|
extern int nserver_102, myrank_102; |
extern int ox_need_conv; |
extern int ox_need_conv; |
int ox_usr1_sent, ox_int_received, critical_when_signal; |
int ox_usr1_sent, ox_int_received, critical_when_signal; |
unsigned int ox_serial; |
unsigned int ox_serial; |
Line 90 static struct mathcap *remote_mc; |
|
Line 91 static struct mathcap *remote_mc; |
|
static int remote_mc_len; |
static int remote_mc_len; |
|
|
void mclist_to_mc(LIST mclist,struct mathcap *mc); |
void mclist_to_mc(LIST mclist,struct mathcap *mc); |
|
Obj asir_pop_one(); |
|
void asir_push_one(Obj); |
|
|
#if defined(VISUAL) |
#if defined(VISUAL) || defined(__MINGW32__) || defined(__MINGW64__) |
/* XXX : mainly used in engine2000/io.c, but declared here */ |
/* XXX : mainly used in engine2000/io.c, but declared here */ |
|
typedef void *HANDLE; |
HANDLE hStreamNotify,hStreamNotify_Ack; |
HANDLE hStreamNotify,hStreamNotify_Ack; |
|
|
void cleanup_events() |
void cleanup_events() |
Line 106 void cleanup_events() |
|
Line 110 void cleanup_events() |
|
|
|
void ox_resetenv(char *s) |
void ox_resetenv(char *s) |
{ |
{ |
#if defined(VISUAL) |
#if defined(VISUAL) || defined(__MINGW32__) || defined(__MINGW64__) |
cleanup_events(); |
cleanup_events(); |
#endif |
#endif |
fprintf(stderr,"%s\n",s); |
fprintf(stderr,"%s\n",s); |
|
#if defined(__MINGW32__) || defined(__MINGW64__) |
|
fflush(stderr); |
|
#endif |
LONGJMP(ox_env,1); |
LONGJMP(ox_env,1); |
} |
} |
|
|
Line 119 static int available_cmo[] = { |
|
Line 126 static int available_cmo[] = { |
|
CMO_ZZ, CMO_QQ, CMO_ZERO, |
CMO_ZZ, CMO_QQ, CMO_ZERO, |
CMO_DMS_GENERIC, CMO_DMS_OF_N_VARIABLES, |
CMO_DMS_GENERIC, CMO_DMS_OF_N_VARIABLES, |
CMO_RING_BY_NAME, CMO_DISTRIBUTED_POLYNOMIAL, |
CMO_RING_BY_NAME, CMO_DISTRIBUTED_POLYNOMIAL, |
|
CMO_RATIONAL, |
CMO_RECURSIVE_POLYNOMIAL, CMO_UNIVARIATE_POLYNOMIAL, |
CMO_RECURSIVE_POLYNOMIAL, CMO_UNIVARIATE_POLYNOMIAL, |
CMO_INDETERMINATE, |
CMO_INDETERMINATE, |
CMO_TREE, |
CMO_TREE, CMO_BIGFLOAT, |
0 |
0 |
}; |
}; |
|
|
static int ox_asir_available_sm[] = { |
static int asir_available_sm[] = { |
SM_dupErrors, SM_getsp, SM_popSerializedLocalObject, |
SM_dupErrors, SM_getsp, SM_popSerializedLocalObject, |
SM_popCMO, SM_popString, SM_pushCMOtag, SM_setName, |
SM_popCMO, SM_popString, SM_pushCMOtag, SM_setName, |
SM_evalName, SM_executeStringByLocalParser, |
SM_evalName, SM_executeStringByLocalParser, |
Line 136 static int ox_asir_available_sm[] = { |
|
Line 144 static int ox_asir_available_sm[] = { |
|
0 |
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_executeFunctionSync, |
|
SM_set_rank_102, SM_tcp_accept_102, SM_tcp_connect_102, SM_reset_102, |
|
SM_bcast_102, SM_reduce_102, |
|
0 |
|
}; |
|
|
static int ox_plot_available_sm[] = { |
static int ox_plot_available_sm[] = { |
SM_dupErrors, SM_getsp, SM_popSerializedLocalObject, |
SM_dupErrors, SM_getsp, SM_popSerializedLocalObject, |
SM_popCMO, SM_popString, SM_setName, |
SM_popCMO, SM_popString, SM_setName, |
SM_evalName, SM_executeStringByLocalParser, |
SM_evalName, SM_executeStringByLocalParser, |
SM_executeFunction, SM_shutdown, SM_pops, |
SM_executeFunction, SM_shutdown, SM_pops, |
SM_mathcap, SM_setMathcap, |
SM_mathcap, SM_setMathcap, SM_nop, |
0 |
0 |
}; |
}; |
|
|
Line 175 void create_my_mathcap(char *system) |
|
Line 196 void create_my_mathcap(char *system) |
|
|
|
/* sm tag */ |
/* sm tag */ |
n0 = 0; |
n0 = 0; |
if ( !strcmp(system,"ox_asir") ) { |
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++ ) { |
for ( i = 0; k = ox_asir_available_sm[i]; i++ ) { |
NEXTNODE(n0,n); MKUSINT(t,k); BDY(n) = (pointer)t; |
NEXTNODE(n0,n); MKUSINT(t,k); BDY(n) = (pointer)t; |
} |
} |
Line 374 void end_critical() { |
|
Line 399 void end_critical() { |
|
critical_when_signal = 0; |
critical_when_signal = 0; |
if ( ox_usr1_sent ) { |
if ( ox_usr1_sent ) { |
ox_usr1_sent = 0; |
ox_usr1_sent = 0; |
#if !defined(VISUAL) |
#if !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__) |
ox_usr1_handler(SIGUSR1); |
ox_usr1_handler(SIGUSR1); |
#else |
#else |
ox_usr1_handler(0); |
ox_usr1_handler(0); |
Line 385 void end_critical() { |
|
Line 410 void end_critical() { |
|
} |
} |
} |
} |
|
|
|
extern NODE user_int_handler; |
|
|
void ox_usr1_handler(int sig) |
void ox_usr1_handler(int sig) |
{ |
{ |
#if !defined(VISUAL) |
NODE t; |
|
|
|
#if !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__) |
signal(SIGUSR1,ox_usr1_handler); |
signal(SIGUSR1,ox_usr1_handler); |
#endif |
#endif |
if ( critical_when_signal ) { |
if ( critical_when_signal ) { |
Line 395 void ox_usr1_handler(int sig) |
|
Line 424 void ox_usr1_handler(int sig) |
|
ox_usr1_sent = 1; |
ox_usr1_sent = 1; |
} else { |
} else { |
ox_flushing = 1; |
ox_flushing = 1; |
|
if ( user_int_handler ) { |
|
fprintf(stderr, |
|
"usr1 : calling the registered exception handlers..."); |
|
for ( t = user_int_handler; t; t = NEXT(t) ) |
|
bevalf((FUNC)BDY(t),0); |
|
fprintf(stderr, "done.\n"); |
|
} |
ox_resetenv("usr1 : return to toplevel by SIGUSR1"); |
ox_resetenv("usr1 : return to toplevel by SIGUSR1"); |
} |
} |
|
#if defined(__MINGW32__) || defined(__MINGW64__) |
|
fflush(stderr); |
|
#endif |
} |
} |
|
|
void clear_readbuffer() |
void clear_readbuffer() |
Line 432 void wait_for_data(int s) |
|
Line 471 void wait_for_data(int s) |
|
{ |
{ |
return; |
return; |
} |
} |
|
|
|
void wait_for_data_102(int rank) |
|
{ |
|
return; |
|
} |
#else |
#else |
int ox_data_is_available(int s) |
int ox_data_is_available(int s) |
{ |
{ |
Line 444 void wait_for_data(int s) |
|
Line 488 void wait_for_data(int s) |
|
int sock; |
int sock; |
|
|
if ( !FP_DATA_IS_AVAILABLE(iofp[s].in) ) { |
if ( !FP_DATA_IS_AVAILABLE(iofp[s].in) ) { |
#if defined(VISUAL) |
#if defined(VISUAL) || defined(__MINGW32__) || defined(__MINGW64__) |
sock = iofp[s].in->fildes; |
sock = iofp[s].in->fildes; |
FD_ZERO(&r); |
FD_ZERO(&r); |
FD_SET((unsigned int)sock,&r); |
FD_SET((unsigned int)sock,&r); |
Line 457 void wait_for_data(int s) |
|
Line 501 void wait_for_data(int s) |
|
#endif |
#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) || defined(__MINGW32__) || defined(__MINGW64__) |
|
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 |
|
} |
|
} |
|
#endif |
|
|
void ox_send_data(int s,pointer p) |
void ox_send_data(int s,pointer p) |
{ |
{ |
ERR err; |
ERR err; |
|
|
if ( ox_check && !ox_check_cmo(s,(Obj)p) ) { |
if ( ox_check && !ox_check_cmo(s,(Obj)p) ) { |
create_error(&err,ox_serial,"ox_send_data : Mathcap violation"); |
create_error(&err,ox_serial,"ox_send_data : Mathcap violation",0); |
p = (pointer)err; |
p = (pointer)err; |
} |
} |
begin_critical(); |
begin_critical(); |
Line 475 void ox_send_data(int s,pointer p) |
|
Line 539 void ox_send_data(int s,pointer p) |
|
end_critical(); |
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 data; |
|
int r,mask,id,src,dst; |
|
|
|
r = myrank_102-root; |
|
if ( r == 0 ) |
|
data = (Obj)asir_pop_one(); |
|
|
|
if ( r < 0 ) r += nserver_102; |
|
for ( mask = 1; mask < nserver_102; mask <<= 1 ) |
|
if ( r&mask ) { |
|
src = myrank_102-mask; |
|
if ( src < 0 ) src += nserver_102; |
|
ox_recv_102(src,&id,&data); |
|
break; |
|
} |
|
for ( mask >>= 1; mask > 0; mask >>= 1 ) |
|
if ( (r+mask) < nserver_102 ) { |
|
dst = myrank_102+mask; |
|
if ( dst >= nserver_102 ) dst -= nserver_102; |
|
ox_send_data_102(dst,data); |
|
} |
|
asir_push_one(data); |
|
} |
|
|
|
/* func : an arithmetic funcion func(vl,a,b,*c) */ |
|
|
|
void ox_reduce_102(int root,void (*func)()) |
|
{ |
|
Obj data,data0,t; |
|
int r,mask,id,src,dst; |
|
|
|
r = myrank_102-root; |
|
if ( r < 0 ) r += nserver_102; |
|
data = (Obj)asir_pop_one(); |
|
for ( mask = 1; mask < nserver_102; mask <<= 1 ) |
|
if ( r&mask ) { |
|
dst = (r-mask)+root; |
|
if ( dst >= nserver_102 ) dst -= nserver_102; |
|
ox_send_data_102(dst,data); |
|
break; |
|
} else { |
|
src = r+mask; |
|
if ( src < nserver_102 ) { |
|
src += root; |
|
if ( src >= nserver_102 ) src -= nserver_102; |
|
ox_recv_102(src,&id,&data0); |
|
(*func)(CO,data,data0,&t); data = t; |
|
} |
|
} |
|
asir_push_one(r?0:data); |
|
} |
|
|
void ox_send_cmd(int s,int id) |
void ox_send_cmd(int s,int id) |
{ |
{ |
if ( ox_check && !check_sm_by_mc(s,id) ) |
if ( ox_check && !check_sm_by_mc(s,id) ) |
Line 496 void ox_send_sync(int s) |
|
Line 626 void ox_send_sync(int s) |
|
end_critical(); |
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) |
void ox_send_local_data(int s,Obj p) |
{ |
{ |
begin_critical(); |
begin_critical(); |
Line 507 void ox_send_local_data(int s,Obj p) |
|
Line 646 void ox_send_local_data(int s,Obj p) |
|
end_critical(); |
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) |
void ox_send_local_ring(int s,VL vl) |
{ |
{ |
begin_critical(); |
begin_critical(); |
Line 518 void ox_send_local_ring(int s,VL vl) |
|
Line 668 void ox_send_local_ring(int s,VL vl) |
|
end_critical(); |
end_critical(); |
} |
} |
|
|
|
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 ox_recv(int s, int *id, Obj *p) |
{ |
{ |
unsigned int cmd,serial; |
unsigned int cmd,serial; |
Line 547 unsigned int ox_recv(int s, int *id, Obj *p) |
|
Line 708 unsigned int ox_recv(int s, int *id, Obj *p) |
|
return serial; |
return serial; |
} |
} |
|
|
|
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) |
void ox_get_result(int s,Obj *rp) |
{ |
{ |
int id; |
int id; |
Line 577 void ox_read_int(int s, int *n) |
|
Line 767 void ox_read_int(int s, int *n) |
|
read_int((FILE *)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) |
void ox_read_cmo(int s, Obj *rp) |
{ |
{ |
ox_need_conv = iofp[s].conv; |
ox_need_conv = iofp[s].conv; |
read_cmo((FILE *)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) |
void ox_read_local(int s, Obj *rp) |
{ |
{ |
int id; |
int id; |
Line 603 void ox_read_local(int s, Obj *rp) |
|
Line 806 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) |
void ox_write_int(int s, int n) |
{ |
{ |
ox_need_conv = iofp[s].conv; |
ox_need_conv = iofp[s].conv; |
write_int((FILE *)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) |
void ox_write_cmo(int s, Obj obj) |
{ |
{ |
ox_need_conv = iofp[s].conv; |
ox_need_conv = iofp[s].conv; |
write_cmo((FILE *)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) |
int ox_check_cmo(int s, Obj obj) |
{ |
{ |
NODE m; |
NODE m; |
Line 646 int ox_check_cmo(int s, Obj obj) |
|
Line 881 int ox_check_cmo(int s, Obj obj) |
|
return check_by_mc(s,OX_DATA,CMO_ZZ); |
return check_by_mc(s,OX_DATA,CMO_ZZ); |
else |
else |
return check_by_mc(s,OX_DATA,CMO_QQ); |
return check_by_mc(s,OX_DATA,CMO_QQ); |
case N_R: |
case N_R: case N_B: |
return 1; |
return 1; |
default: |
default: |
return 0; |
return 0; |
Line 659 int ox_check_cmo(int s, Obj obj) |
|
Line 894 int ox_check_cmo(int s, Obj obj) |
|
return 1; |
return 1; |
case O_QUOTE: /* XXX */ |
case O_QUOTE: /* XXX */ |
return 1; |
return 1; |
|
case O_MAT: /* MAT is sent as a list */ |
|
return 1; |
default: |
default: |
return 0; |
return 0; |
} |
} |
Line 707 void ox_flush_stream(int s) |
|
Line 944 void ox_flush_stream(int s) |
|
{ |
{ |
if ( ox_batch ) |
if ( ox_batch ) |
return; |
return; |
#if defined(VISUAL) |
#if defined(VISUAL) || defined(__MINGW32__) || defined(__MINGW64__) |
if ( _fileno(&iofp[s].out->fp) < 0 ) |
if ( _fileno(&iofp[s].out->fp) < 0 ) |
cflush(iofp[s].out); |
cflush(iofp[s].out); |
else |
else |
Line 721 void ox_flush_stream(int s) |
|
Line 958 void ox_flush_stream(int s) |
|
|
|
void ox_flush_stream_force(int s) |
void ox_flush_stream_force(int s) |
{ |
{ |
#if defined(VISUAL) |
#if defined(VISUAL) || defined(__MINGW32__) || defined(__MINGW64__) |
if ( _fileno(&iofp[s].out->fp) < 0 ) |
if ( _fileno(&iofp[s].out->fp) < 0 ) |
cflush(iofp[s].out); |
cflush(iofp[s].out); |
else |
else |
Line 731 void ox_flush_stream_force(int s) |
|
Line 968 void ox_flush_stream_force(int s) |
|
else |
else |
#endif |
#endif |
fflush((FILE *)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) || defined(__MINGW32__) || defined(__MINGW64__) |
|
cflush(iofp_102[rank].out); |
|
#elif MPI |
|
cflush(iofp_102[rank].out); |
|
#else |
|
fflush(iofp_102[rank].out); |
|
#endif |
} |
} |