void control_init() { // Add handler so that received message are treated correctly // Class 1: control messages optimsoc_mp_simple_init(); optimsoc_mp_simple_addhandler(NOC_CLASS_FIFO, &control_msg_handler); optimsoc_mp_simple_enable(); or1k_interrupts_enable(); }
// Here we go.. int main() { // Initialize the OpTiMSoC library optimsoc_init(0); optimsoc_mp_simple_init(); // Add a handler for class 0 packets to the mpsimple message passing // driver. The driver will execute recv (see definition above) each // time a packet arrives. optimsoc_mp_simple_addhandler(0,&recv); or1k_interrupts_enable(); // Determine my rank and total number rank = optimsoc_ctrank(); total = optimsoc_ctnum(); // Determine number of rows and columns xcount = workshare[total-1][0]; ycount = workshare[total-1][1]; // Define tracing optimsoc_trace_definesection(0,"initialization"); optimsoc_trace_definesection(1,"compute"); optimsoc_trace_definesection(2,"update"); optimsoc_trace_definesection(3,"barrier"); optimsoc_trace_section(0); // If this rank is not part of the grid, just quit.. if (rank >= xcount*ycount) return -1; // Determine this ranks column and row col = rank % xcount; for(row=0;(row+1)*xcount<=rank;row++) {} // Determine whether this rank is on one of the boundaries leftbound = (col==0); rightbound = (col==xcount-1); topbound = (row==0); bottombound = (row==ycount-1); // The default for xdim and ydim is simple but rounded xdim = (XSIZE/xcount); ydim = (YSIZE/ycount); // The base address is easily calculated based on this xbase = xdim * col; ybase = ydim * row; // And the last in a row and in a column need to get their // dimensions adjusted to match the rounding if (rightbound) xdim = XSIZE - xdim*(xcount-1); if (bottombound) ydim = YSIZE - ydim*(ycount-1); // We start with matrix 0 as initial value and matrix 1 // for the first calculation curmatrix = 1; // Inititalize sufficient memory (remember extra rows and cols) matrix[0] = malloc(sizeof(float)*(xdim+2)*(ydim+2)); matrix[1] = malloc(sizeof(float)*(xdim+2)*(ydim+2)); // Initialize all with zeros for (int x=0;x<xdim+2;x++) { for (int y=0;y<ydim+2;y++) { matrix[0][POS(x,y)] = 0; matrix[1][POS(x,y)] = 0; } } // To see any heat distribution we need a hot spot, that // is here on the upper left corner. if (rank==0) { matrix[0][POS(0,0)] = 9.99; matrix[0][POS(1,0)] = 9.99; matrix[0][POS(0,1)] = 9.99; matrix[0][POS(0,2)] = 9.99; matrix[1][POS(0,0)] = 9.99; matrix[1][POS(1,0)] = 9.99; matrix[1][POS(0,1)] = 9.99; matrix[1][POS(0,2)] = 9.99; } // Allocate memory for the result matrix if (rank==0) { result = malloc(XSIZE*YSIZE*sizeof(float)); } // Call the heat function that does all processing heat(); // Print results after all iterations from core 0 if (rank==0) { for (int y=0;y<YSIZE;y++) { for (int x=0;x<XSIZE;x++) { printf("%.2f ",result[x+y*XSIZE]); } printf("\n"); } } return 0; }
void control_init() { // Add handler so that received message are treated correctly // Class 1: control messages optimsoc_mp_simple_init(); optimsoc_mp_simple_addhandler(MP_NOC_CLASS, &control_msg_handler); }