ConcurrentMarkSweepPolicy::ConcurrentMarkSweepPolicy() { initialize_all(); }
MarkSweepPolicy::MarkSweepPolicy() { initialize_all(); }
/** * Main optimization loop. * Note: this version of code does NOT have special version for sequential * version. Sequential version is slightly lighter than parallel version because * it can use a more efficient operation to maintain the active set. In practice, this * has little effect. Also, it does not need to have a atomic array for maintaining Ax. * For the experiments in the paper, a special sequential code was used for fairness. */ void compute_logreg(shotgun_data * prob, double lambda, double term_threshold, int max_iter, int verbose, bool & all_zero) { all_zero = false; logregprob = prob; //double l1x, loglikelihood; int iterations = 0;//, t=0; long long int num_of_shoots = 0; std::vector<int> shuffled_indices; for(int j=0; j<logregprob->nx; j++) shuffled_indices.push_back(j); Gmax_old = 1e30; // Adjust threshold similarly as liblinear initialize_all(); term_threshold = term_threshold*std::min(pos_y,neg_y)/double(logregprob->ny); while(true) { int active_size = logregprob->nx; num_of_shoots += active_size; // Randomization for(int j=0; j<active_size; j++) { int i = j+rand()%(active_size-j); swap(shuffled_indices[i], shuffled_indices[j]); } /* Main parallel loop */ #pragma omp parallel for for(int s=0; s<active_size; s++) { int x_i = shuffled_indices[s]; shoot_logreg(x_i, lambda); } /* Gmax handling */ Gmax_old = logregprob->Gmax[0]; if (iterations == 0) { Gmax_init = Gmax_old; } iterations++; //std::cout << Gmax.get_value() << " " << Gmax_init << " " << term_threshold*Gmax_init << std::endl; if (iterations > max_iter && max_iter>0) { mexPrintf("Exceeded max iterations: %d\n", max_iter); break; } for(int i=0; i<logregprob->nx; i++) shuffled_indices[i] = i; active_size = logregprob->nx; for(int s=0; s<active_size; s++) { int j = shuffled_indices[s]; if (!active[j]) { active_size--; swap(shuffled_indices[s], shuffled_indices[active_size]); s--; } } if (logregprob->Gmax[0] <= term_threshold*Gmax_init) { // std::cout << active_size << std::endl; if (active_size == logregprob->nx) { printf("Encountered all zero solution! try to decrease lambda\n"); all_zero = true; break; } else { Gmax_old = 1e30; for(int i=0; i<logregprob->nx; i++) active[i] = true; active_size=logregprob->nx; recompute_expAx(); continue; } } if (verbose){ double l1x=0, loglikelihood=0; int l0=0; double obj = compute_objective_logreg(lambda, &l1x, &loglikelihood, &l0, NULL); printf("objective is: %g l1: %g loglikelihood %g l0: %d\n", obj, l1x, loglikelihood, l0); if (l1x == 0) all_zero = true; } }// end iterations if (!verbose){ double l1x=0, loglikelihood=0; int l0=0; double obj = compute_objective_logreg(lambda, &l1x, &loglikelihood, &l0, NULL); if (l1x == 0) all_zero = true; printf("objective is: %g l1: %g loglikelihood %g l0: %d\n", obj, l1x, loglikelihood, l0); } delete[] active; delete[] xjneg; mexPrintf("Finished Shotgun CDN in %d iterations\n", iterations); }
int main(){ initialize_all(); char buf[30]; uint8_t uart_data; // Print Device ID uint64_t this_device_id = (((uint64_t) NRF_FICR->DEVICEID[1] << 32) | ((uint64_t) NRF_FICR->DEVICEID[0])); sprintf((char*)buf, "ID: %llx\n", this_device_id); simple_uart_putstring(buf); uint8_t availability; bool radio_executed = false; // main application loop while (1) { //All the mugs that will be invited have been set if (is_connected()) { // Deal with radios sd_softdevice_disable(); radio_configure(); // simple_uart_putstring("Configured radio\n"); // simple_uart_putstring("Disabled soft device\n"); // END - Deal with radios bool disovery_complete = false; bool all_final_state = true; int8_t current_mug = 0; while (!disovery_complete){ uint64_t device_id = 0; // vibration_update(); if (receive_packet(20)){ device_id = packet[1]; if (this_device_id == device_id){ if (packet[0] == 0xcfcf){ // Master init sequence simple_uart_putstring("Got init!\n"); packet[0] = 0xaf; // Send ACK to Master send_packet(1); // ... 3 times ... simple_uart_putstring("[a]ccept or [r]eject:\n"); uart_data = simple_uart_get(); switch (uart_data) { case 'a': availability = 0xaa; simple_uart_putstring("Accepted\n"); break; case 'r': availability = 0xff; simple_uart_putstring("Rejected\n"); break; } uart_data = simple_uart_get(); } else if (packet[0] == 0xabab) { // Master poll availability simple_uart_putstring("Sent availability status!\n"); packet[0] = availability; // Send ACK to Master send_packet(1); } else if (packet[0] == 0xdede) { // Master kettle boiling simple_uart_putstring("Got invitation!\n"); packet[0] = 0xaf; // Send ACK to Master send_packet(1); // ... 3 times ... for (uint8_t i=0; i<100; i++){ nrf_gpio_pin_toggle(0); nrf_delay_ms(200); } } else { sprintf((char*)buf, "Brocken command: %llx\n", packet[0]); simple_uart_putstring(buf); } } else { simple_uart_putstring("Not applicable packet\n"); sprintf((char*)buf, "Target: %llx\n", packet[1]); simple_uart_putstring(buf); sprintf((char*)buf, "Command: %llx\n", packet[0]); simple_uart_putstring(buf); } } if (bump_action()) { disovery_complete = true; // uint8_t bump_evt = 1; // ble_update_bump(&bump_evt) } } // Deal with radios sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_RC_250_PPM_1000MS_CALIBRATION,app_error_handler); // simple_uart_putstring("Enabled soft device\n"); // END - Deal with radios // uint8_t bump_val = 1; // ble_update_bump(&bump_val); // simple_uart_putstring("They see me bumpin', I see 'em hatin'!\n"); disovery_complete = false; // RSVP_App(); //sends MUG information back to app via ble, defined in slip_ble.c } //debug_ble_ids(); // vibration_update(); app_sched_execute(); nrf_delay_ms(500); } }