void loop(void* arg) { int (*test)(int, int) = (int (*)(int, int))arg; int i, j; int res; //communicator_t* loc_com = &comm; communicator_t* loc_com = &comm_world; //if (test == barrier_master || test == barrier_slave || // test == broadcast_master || test == broadcast_slave) { // loc_com = &comm_world; //} //communicator_t stack_com; //stack_com.barrier_set = loc_com->barrier_set; //for(int i = 0; i < loc_com->count; i++) { // stack_com.addr[i] = loc_com->addr[i]; //} //stack_com.count = loc_com->count; //stack_com.msg_size = loc_com->msg_size; DEBUGGER("Initial test run\n"); /* Allow routing/cache setup ahead of time */ test(1,1024); DEBUGGER("Initial test run done\n"); for( i=0; i < num_sizes; i++){ if (flush & FLUSH_BETWEEN_SIZES) { inval_dcache(); inval_mcache(); } for( j=1; j <= repeat_count; j++){ if (flush & FLUSH_BETWEEN_REPEATS) { inval_dcache(); inval_mcache(); } mp_barrier(loc_com); //mp_barrier(&stack_com); res = test(iterations, sizes[i]); my_two_printf("%u\t%i\n",sizes[i],res); mp_barrier(loc_com); //mp_barrier(&stack_com); } } inval_dcache(); inval_mcache(); if(get_cpuid() != 0){ int ret = 0; corethread_exit(&ret); } return; }
void func_worker_1(void* arg) { int worker_1_param = *((int*)arg); // For each of the messages that is received for (int i = 0; i < 5; ++i) { mp_recv(&chan1); for(int j = 0; j < chan1.buf_size; j++){ // Copy the received data to the send buffer int to_offset = i * chan1.buf_size + j; volatile char _SPM * copy_to; volatile char _SPM * copy_from; copy_to = (volatile char _SPM *)chan2.write_buf + to_offset; copy_from = (volatile char _SPM *)chan1.read_buf + j; // Like a Cesar code, shifting the ascii alphabet *copy_to = (*copy_from)+(char)worker_1_param; } // Acknowledge the received data. mp_ack(&chan1); } mp_barrier(&comm); mp_send(&chan2); int ret = 0; corethread_exit(&ret); return; }
int barrier_slave(int cnt, int bytes) { int i; for (i=0; i<cnt; i++) { if (flush & FLUSH_BETWEEN_ITERATIONS) { inval_dcache(); //inval_mcache(); } mp_barrier(&comm_world); } return 0; }
int barrier_master(int cnt, int bytes) { int i; int total = 0; TIMER_START; for (i=0; i<cnt; i++) { if (flush & FLUSH_BETWEEN_ITERATIONS) { inval_dcache(); //inval_mcache(); } mp_barrier(&comm_world); } TIMER_STOP; total = TIMER_ELAPSED; total -= calibrate_cache_flush(cnt); return(total/cnt); /* usec */ }
int main() { puts("Master"); corethread_t worker_1 = 2; // For now the core ID int worker_1_param = 1; char send_data[] = "Hello World!, Sending messages is cool!"; char recv_data[40]; // Initialization of message passing buffers // mp_chan_init() return false if local and remote // addresses are not aligned to words if (!mp_chan_init(&chan1, get_cpuid(), worker_1, MP_CHAN_1_BUF_SIZE, MP_CHAN_1_NUM_BUF)) { abort(); } if (!mp_chan_init(&chan2, worker_1, get_cpuid(), MP_CHAN_2_BUF_SIZE, MP_CHAN_2_NUM_BUF)) { abort(); } puts("Initialized buffers"); if (!mp_communicator_init(&comm, 2, cores, 0)) { abort(); } puts("Initialized barrier"); corethread_create(&worker_1,&func_worker_1,(void*)&worker_1_param); int i = 0; // While there is still data to be sent while(i < sizeof(send_data)) { int chunk = 0; if ( sizeof(send_data)-i >= chan1.buf_size) { // If the remaining data is more than the size of the buffer chunk = chan1.buf_size; } else { // The remaining data all fits in a buffer chunk = sizeof(send_data)-i; } // Copy the chunk of data to the write buffer for (int j = 0; j < chunk; ++j) { *((volatile char _SPM *)chan1.write_buf+j) = send_data[i+j]; } // Send the chunk of data mp_send(&chan1); i += chunk; } puts("Messages sent"); mp_barrier(&comm); puts("Barrier reached"); mp_recv(&chan2); puts("Message recv"); // Copy the received data to the recv_data array for(int i = 0; i < sizeof(recv_data)-1; i++) { recv_data[i] = (*((volatile char _SPM *)chan2.read_buf+i)-worker_1_param); } // Acknowledge the received data mp_ack(&chan2); recv_data[39] = '\0'; puts(recv_data); int* res; corethread_join(worker_1,&res); return *res; }