/***************************************/ /* Sample of amdc Direct Communication */ /* Kristi Cablk */ /***************************************/ /* This simple program demostrates AMDC direct communication between two processes. Process 0 will send some messages to process 1, which recives them, prints the data, and then sends the same message back to process 0 who prints the data again. */ #include #include "amdc96.h" /* Define the message tags */ #define TEST 1L /* globals */ Location my_loc; LocName my_name; int my_id; /* Send a message to another process */ void p_send(int dst, Tag t, char *body, int leng) { Message p; LocName L; L = amdc_0DLocName(AMDC_PROCESS_SYMBOL); L.X[0] = dst; p = amdc_rawMsg(leng); memcpy((char*)p, body, leng); amdc_sendToAs(p,L,t); } /* Receive a message */ Message p_recv(Tag t) { Message p; while ((p=amdc_getLoc(my_loc, t)) == NULL) { amdc_pollBlock(); } return p; } int Main() { int n; int test; int test2; Message p; my_loc = amdc_getMyLoc(); my_name = amdc_getNameOfLoc(my_loc); my_id = amdc_getMyId(); test = 1; printf("\nI'm node %d\n",my_id); if (my_id == 0 ) { printf("starting with %d nodes....\n", amdc_getNumNodes()); while (test<=10) { /* send test with some data */ p_send(1, TEST, (char *)&test, sizeof(int) ); /* receive message back */ p = p_recv(TEST); printf("\nprocess 0 received the message from process 1\n"); test2 = *(int*)p; printf("Value received is %d \n",test2); test++; } } else if (my_id == 1) { while (test<=10) { p = p_recv(TEST); printf("\nprocess 1 received the message from process 0\n"); test = *(int*)p; printf("Value received is %d \n",test); /* send the message back */ p_send(0, TEST, (char *)&test, sizeof(int) ); test++; } } else { printf("this program only supports 2 nodes!\n"); } }