/**********************************************************/ /* From: Kuang-chun Tao */ /* Document for the Programming Techniques with Processes */ /* for Direct Communication. */ /* This program is composed of a number of processes that */ /* communicate directly with each other. For example, */ /* process 0 sends a message to process1, process 1 sends */ /* a message to process 2, and then process 0 receives */ /* a message from process 2, process 1 receives a message */ /* from process 0, and so on. */ /**********************************************************/ #include "amdc96.h" #include int x, y, z, tag = 0; char *str = "abc"; Location my_loc; LocName my_name; void p_send(int dst, Tag t, char *body, int leng) { Message p; LocName L; L = amdc_1DLocName(AMDC_PROCESS_SYMBOL, dst); p = amdc_rawMsg(leng); memcpy((char *)p, body, leng); amdc_sendToAs(p, L, t); printf("Process %d is sending message %s..\n", amdc_getMyId, body); } Message p_recv(Tag t) { Message p; while((p = amdc_getLoc(my_loc, t)) == NULL) amdc_pollBlock(); return p; } int Main() { Message p; my_loc = amdc_getMyLoc(); my_name = amdc_getNameOfLoc(my_loc); while(1) { x = amdc_getMyId(); x++; y = amdc_getNumNodes(); y--; if(x > y) x = 0; p_send(x, tag, str, strlen(str)); sleep(2); z = amdc_getMyId(); z--; if(z < 0) z = y; p = p_recv(tag); if(p) printf("Process %d is receiving message %s...\n", amdc_getMyId, p); } }