#include #include #include "mimd.h" #include "sort_util.h" /******************************************************************* swap some memory ********************************************************************/ void memswp(void *p1,void *p2,int size) { register int *d1 = p1,*d2 = p2; { register int a1,a2,a3,a4; register int b1,b2,b3,b4; while (size>(4*sizeof(int))) { a1=d1[0];a2=d1[1];a3=d1[2];a4=d1[3]; b1=d2[0];b2=d2[1];b3=d2[2];b4=d2[3]; d2[0]=a1;d2[1]=a2;d2[2]=a3;d2[3]=a4; d1[0]=b1;d1[1]=b2;d1[2]=b3;d1[3]=b4; d1+=4;d2+=4; size -= 4*sizeof(int); } } { register int a1,b1; while (size>sizeof(int)) { a1=d1[0]; b1=d2[0]; d2[0]=a1; d1[0]=b1; d1++;d2++; size -= sizeof(int); } } { register char a1,b1; register char *c1=(char *)d1,*c2=(char *)d2; while (size>0) { a1= *c1; b1= *c2; *c2=a1; *c1=b1; c1++; c2++; size--; } } } /******************************************************************* panic ********************************************************************/ void MM_Panic(const char *msg) { MIMD_Panic(msg); } /******************************************************************* swap memory areas between two cells ********************************************************************/ void swap_memory(int node,void *ptr,int to_receive,int to_send) { /* printf("\nnode %d with %d to_recv %d to_send %d\n",NODE_NUMBER,node,to_receive,to_send); */ #ifndef CM5 { int BufSize = 32*(1<<10); if (NODE_NUMBER < node) { char *Rptr = ((char *)ptr) + to_receive; char *Sptr = ((char *)ptr) + to_send; int recv,send; #if BLOCKING void *buf = malloc(BufSize); if (!buf) { printf("Failed to malloc for swap_memory\n"); exit(0); } #endif while (to_receive>0 || to_send>0) { recv = MIN(to_receive,BufSize); send = MIN(to_send,BufSize); #if BLOCKING if (send) memcpy(buf,Sptr-send,send); if (recv) MIMD_Recv(node,Rptr-recv,recv); if (send) MIMD_Send(node,buf,send); #else if (send) MIMD_Send(node,Sptr-send,send); if (recv) MIMD_Recv(node,Rptr-recv,recv); #endif to_receive -= recv; to_send -= send; Rptr -= recv; Sptr -= send; } #if BLOCKING free(buf); #endif } else { char *Rptr = ((char *)ptr) + to_receive; char *Sptr = ((char *)ptr) + to_send; int recv,send; while (to_receive>0 || to_send>0) { recv = MIN(to_receive,BufSize); send = MIN(to_send,BufSize); if (send) MIMD_Send(node,Sptr-send,send); if (recv) MIMD_Recv(node,Rptr-recv,recv); to_receive -= recv; to_send -= send; Rptr -= recv; Sptr -= send; } } } #else #if 1 { int BufSize = 30*(1<<10); char *Cptr = (char *)ptr; while (to_receive>0 || to_send>0) { int recv = MIN(to_receive,BufSize); int send = MIN(to_send,BufSize); CMMD_send_and_receive(node,0,Cptr,recv,node,0,Cptr,send); to_receive -= recv; to_send -= send; Cptr += BufSize; } } #else CMMD_send_and_receive(node,1,ptr,to_receive,node,1,ptr,to_send); #endif #endif /* printf("done\n"); */ } /********************************************************************** send some data after touching it to make sure it's paged in **********************************************************************/ void VnodeSend(int to,char *ptr,int size,int swapin) { /* if (swapin) touch_data(ptr,size,1); MIMD_Send(get_vnode_node(to),ptr,size); */ MIMD_Send(to,ptr,size); } /********************************************************************** recv some data after touching it to make sure it's paged in **********************************************************************/ void VnodeRecv(int from,char *ptr,int size,int swapin) { /* if (swapin) touch_data(ptr,size,0); MIMD_Recv(get_vnode_node(from),ptr,size); */ MIMD_Recv(from,ptr,size); } /******************************************************************* swap memory areas between two cells - touching as necessary ********************************************************************/ void VnodeSwap(int node,void *ptr,int to_receive,int to_send) { /* touch_data(ptr,to_receive,0); touch_data(ptr,to_send,1); swap_memory(get_vnode_node(node),ptr,to_receive,to_send); */ swap_memory(node,ptr,to_receive,to_send); } int log2(int x) { int r=0; while ((1<>((bits-1)-i))&1)<