int main() { corethread_t slave1 = 1; corethread_t slave2 = 2; corethread_t slave3 = 3; corethread_t slave4 = 4; corethread_t slave5 = 5; corethread_t slave6 = 6; corethread_t slave7 = 7; corethread_t slave8 = 8; if (!mp_chan_init(&m2s, get_cpuid(), slave4, BUFFER_SIZE, 2)) { abort(); } if (!mp_chan_init(&s2m, slave4, get_cpuid(), BUFFER_SIZE, 2)) { abort(); } if (!mp_communicator_init(&comm, 2, cores, 0)) { abort(); } if (!mp_communicator_init(&comm_world, sizeof(cores_world)/sizeof(cores_world[0]), cores_world, BUFFER_SIZE)) { abort(); } int* ret; /* set up the run */ //corethread_create(&slave,&loop,(void*)roundtrip_slave); /* run appropriate test */ // // TEST_LATENCY // puts("Latency (usecs)"); // corethread_create(&slave4,&loop,(void*)latency_slave); // loop(latency_master); // corethread_join(slave4,(void**)&ret); // // // TEST_ROUNDTRIP // puts("Roundtrip (Transactions/sec)"); // corethread_create(&slave4,&loop,(void*)roundtrip_slave); // loop(roundtrip_master); // corethread_join(slave4,(void**)&ret); // // // TEST_BANDWIDTH // puts("Bandwidth (KB/sec)"); // corethread_create(&slave4,&loop,(void*)bandwidth_slave); // loop(bandwidth_master); // corethread_join(slave4,(void**)&ret); // // TEST_BIBANDWIDTH // puts("Bibandwidth"); // corethread_create(&slave4,&loop,(void*)bibandwidth_slave); // loop(bibandwidth_master); // corethread_join(slave4,(void**)&ret); // // // TEST_REDUCE // puts("Reduce"); // corethread_create(&slave4,&loop,(void*)reduce_slave); // loop(reduce_master); // corethread_join(slave4,(void**)&ret); // // // TEST_ALLREDUCE // puts("Allreduce"); // corethread_create(&slave4,&loop,(void*)allreduce_slave); // loop(allreduce_master); // corethread_join(slave4,(void**)&ret); // // // TEST_ALLTOALL // puts("Alltoall"); // corethread_create(&slave4,&loop,(void*)alltoall_slave); // loop(alltoall_master); // corethread_join(slave4,(void**)&ret); ///////////////////////////////////////////////////////////////////////////// // TEST_BARRIER ///////////////////////////////////////////////////////////////////////////// puts("Barrier (usecs)"); for(int i = 0; i < sizeof(cores_world)/sizeof(cores_world[0]); i++) { if (i != NOC_MASTER) { if(corethread_create((corethread_t*)&cores_world[i],&loop,(void*)barrier_slave) != 0){ printf("Corethread %d not created\n",i); } } } loop(barrier_master); //puts("Master finished"); for (int i = 0; i < sizeof(cores_world)/sizeof(cores_world[0]); ++i) { if (i != NOC_MASTER) { corethread_join((corethread_t)cores_world[i],(void**)&ret); //printf("Slave %d joined\n",i); } } // ///////////////////////////////////////////////////////////////////////////// // // TEST_BROADCAST // ///////////////////////////////////////////////////////////////////////////// // puts("Broadcast (KB/sec)"); // for(int i = 0; i < sizeof(cores_world)/sizeof(cores_world[0]); i++) { // if (i != NOC_MASTER) { // if(corethread_create((corethread_t*)&cores_world[i],&loop,(void*)broadcast_slave) != 0){ // printf("Corethread %d not created\n",i); // } // } // } // loop(broadcast_master); // //puts("Master finished"); // for (int i = 0; i < sizeof(cores_world)/sizeof(cores_world[0]); ++i) { // if (i != NOC_MASTER) { // corethread_join((corethread_t)cores_world[i],(void**)&ret); // //printf("Slave %d joined\n",i); // } // } exit(0); }
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; }