bool hwloc::bind_this_thread( const std::pair<unsigned,unsigned> coord ) { #if 0 std::cout << "KokkosArray::hwloc::bind_this_thread() at " ; hwloc_get_last_cpu_location( s_hwloc_topology , s_hwloc_location , HWLOC_CPUBIND_THREAD ); print_bitmap( std::cout , s_hwloc_location ); std::cout << " to " ; print_bitmap( std::cout , s_core[ coord.second + coord.first * s_core_topology.second ] ); std::cout << std::endl ; #endif // As safe and fast as possible. // Fast-lookup by caching the coordinate -> hwloc cpuset mapping in 's_core'. return coord.first < s_core_topology.first && coord.second < s_core_topology.second && 0 == hwloc_set_cpubind( s_hwloc_topology , s_core[ coord.second + coord.first * s_core_topology.second ] , HWLOC_CPUBIND_THREAD | HWLOC_CPUBIND_STRICT ); }
int main(int argc, char* argv[]) { format_t format = twam; bitmap_t bitmap; if (argc != 4) { printf("You need to call: %s <inputfile> <outputfile> <imagename> \n",argv[0]); printf(" e.g. %s input.bmp image.h image\n",argv[0]); return 1; } // read bitmap if (read_bitmap_from_file(argv[1], &bitmap)<0) { fprintf(stderr, "Error while opening file '%s'!\n", argv[1]); exit(EXIT_FAILURE); } // print bitmap print_bitmap(&bitmap); switch (format) { case xbm: write_bitmap_as_xbm(argv[2], &bitmap, argv[3]); break; case twam: write_bitmap_as_twam(argv[2], &bitmap, argv[3]); break; } // clean up bitmap free(bitmap.data); return 0; }
static inline void handle_request_timeout() { if(fst == NULL) { return; } //sos_assert(fst != NULL); //DEBUG("handle request timeout, retx = %d\n", fst->retx); fst->retx++; if(fst->retx <= FETCHER_REQUEST_MAX_RETX) { fetcher_bitmap_t *m; uint8_t size = sizeof(fetcher_bitmap_t) + fst->map.bitmap_size; DEBUG_PID(KER_FETCHER_PID,"send request to %d\n", fst->src_addr); print_bitmap(&fst->map); m = (fetcher_bitmap_t *) ker_malloc( size, KER_FETCHER_PID); if( m != NULL ) { memcpy(m, &(fst->map), size); m->key = ehtons( m->key ); post_auto(KER_FETCHER_PID, KER_FETCHER_PID, MSG_FETCHER_REQUEST, size, m, SOS_MSG_RELEASE, fst->src_addr); } restart_request_timer(); } else { DEBUG_PID(KER_FETCHER_PID, "request failed!!!\n"); //codemem_close(&fst->cm, false); send_fetcher_done(); } }
struct SimulationResult* run_simulation() { int rank = get_rank(); int num_processes = get_num_processes(); struct SimulationResult *result = 0; struct StepResult *last_result = 0; // only the master process collects the simulation results if(rank == 0) { result = malloc(sizeof(struct SimulationResult)); result->operations = 0; // set start time gettimeofday(&result->start_time, NULL); } init_map(); MPI_Barrier(MPI_COMM_WORLD); int i = 0; int died = 0; if(rank == 0) { printf("Start Population\n"); } died = get_stats(i, &last_result, result); while(i < MAX_SIMULATION_STEPS && !died) { i++; if(rank == 0) printf("Simulation Step %d\n", i); simulation_step(i); died = get_stats(i, &last_result, result); if(num_processes == 1) { print_bitmap(i); } } MPI_Barrier(MPI_COMM_WORLD); if(rank == 0) { gettimeofday(&result->finish_time, NULL); calc_runtime(result); } return result; }
int8_t fetcher_request(sos_pid_t req_id, sos_shm_t key, uint16_t size, uint16_t src) { uint8_t bitmap_size; //! size of the bitmap in bytes uint16_t num_fragments; uint8_t i; fetcher_state_t *f; fetcher_cam_t *cam; cam = (fetcher_cam_t *) ker_shm_get( KER_FETCHER_PID, key); if( cam == NULL ) return -EINVAL; //if(fst != NULL) return -EBUSY; DEBUG_PID(KER_FETCHER_PID, "fetcher_request, req_id = %d, size = %d, src = %d\n", req_id, size, src); num_fragments = ((size + (FETCHER_FRAGMENT_SIZE - 1))/ FETCHER_FRAGMENT_SIZE); bitmap_size = (uint8_t)((num_fragments + 7)/ 8); //DEBUG("size = %d\n", sizeof(fetcher_state_t) + bitmap_size); f = ker_malloc(sizeof(fetcher_state_t) + bitmap_size, KER_FETCHER_PID); if(f == NULL) { return -ENOMEM; } //DEBUG("num_fragments = %d, bitmap_zie = %d\n", num_fragments, bitmap_size); f->requester = req_id; f->map.key = key; f->map.bitmap_size = bitmap_size; f->src_addr = src; f->num_funcs = 0; f->next = NULL; f->cm = cam->cm; for(i = 0; i < bitmap_size; i++) { f->map.bitmap[i] = 0xff; } if((num_fragments) % 8) { f->map.bitmap[bitmap_size - 1] = (1 << (num_fragments % 8)) - 1; } print_bitmap(&f->map); //! backoff first!!! f->retx = 0; if(fst != NULL) { fetcher_state_t *tmp = fst; cam->status = FETCHING_QUEUED; while(tmp->next != NULL) { tmp = tmp->next; } tmp->next = f; return SOS_OK; } cam->status = FETCHING_STARTED; fst = f; //! setup timer ker_timer_start(KER_FETCHER_PID, FETCHER_REQUEST_TID, FETCHER_REQUEST_BACKOFF_SLOT * ((ker_rand() % FETCHER_REQUEST_MAX_SLOT) + 1)); //DEBUG("request ret = %d\n", ret); return SOS_OK; }
void print_all_map() { int i; printf("========== MAP ==========\n"); for (i=0; i<(NUM_BLOCKS/16); i++) { print_bitmap(&allocated_map[i]); } printf("======== / MAP ==========\n\n"); }
void dump_instruction_capabilities( const instruction_capabilities capabilities ) { print_bitmap( capabilities, INSTRUCTION_GOTO_TABLE, "goto_table" ); print_bitmap( capabilities, INSTRUCTION_WRITE_METADATA, "write_metadata" ); print_bitmap( capabilities, INSTRUCTION_WRITE_ACTIONS, "write_actions" ); print_bitmap( capabilities, INSTRUCTION_APPLY_ACTIONS, "apply_actions" ); print_bitmap( capabilities, INSTRUCTION_CLEAR_ACTIONS, "clear_actions" ); print_bitmap( capabilities, INSTRUCTION_METER, "meter" ); print_bitmap( capabilities, INSTRUCTION_EXPERIMENTER, "experimenter" ); }
bool unbind_this_thread() { if ( ! sentinel() ) return false ; #define HWLOC_DEBUG_PRINT 0 #if HWLOC_DEBUG_PRINT std::cout << "Kokkos::unbind_this_thread() from " ; hwloc_get_cpubind( s_hwloc_topology , s_hwloc_location , HWLOC_CPUBIND_THREAD ); print_bitmap( std::cout , s_hwloc_location ); #endif const bool result = s_hwloc_topology && 0 == hwloc_set_cpubind( s_hwloc_topology , s_process_binding , HWLOC_CPUBIND_THREAD | HWLOC_CPUBIND_STRICT ); #if HWLOC_DEBUG_PRINT std::cout << " to " ; hwloc_get_cpubind( s_hwloc_topology , s_hwloc_location , HWLOC_CPUBIND_THREAD ); print_bitmap( std::cout , s_hwloc_location ); std::cout << std::endl ; #endif return result ; #undef HWLOC_DEBUG_PRINT }
std::pair<unsigned,unsigned> hwloc::get_this_thread_coordinate() { const unsigned n = s_core_topology.first * s_core_topology.second ; std::pair<unsigned,unsigned> coord(0,0); // Using the pre-allocated 's_hwloc_location' to avoid memory // allocation by this thread. This call is NOT thread-safe. hwloc_get_last_cpu_location( s_hwloc_topology , s_hwloc_location , HWLOC_CPUBIND_THREAD ); unsigned i = 0 ; while ( i < n && ! hwloc_bitmap_intersects( s_hwloc_location , s_core[ i ] ) ) ++i ; if ( i < n ) { coord.first = i / s_core_topology.second ; coord.second = i % s_core_topology.second ; } else { std::ostringstream msg ; msg << "KokkosArray::hwloc::get_this_thread_coordinate() FAILED :" ; if ( 0 != s_process_binding && 0 != s_hwloc_location ) { msg << " cpu_location" ; print_bitmap( msg , s_hwloc_location ); msg << " is not a member of the process_cpu_set" ; print_bitmap( msg , s_process_binding ); } else { msg << " not initialized" ; } throw std::runtime_error( msg.str() ); } return coord ; }
int DsLib::list_bitmap(DsTask& ds_task) { uint64_t server_id = ds_task.server_id_; int32_t type = ds_task.list_block_type_; if (type >= 1) { printf("usage: list_bitmap ip type\n type 0: normal bitmap\n type 1: error bitmap\n"); return TFS_ERROR; } printf("server ip: %s,type: %d\n", tbsys::CNetUtil::addrToString(server_id).c_str(), type); ListBitMapMessage req_lbm_msg; int ret_status = TFS_ERROR; req_lbm_msg.set_bitmap_type(type); NewClient* client = NewClientManager::get_instance().create_client(); tbnet::Packet* ret_msg = NULL; ret_status = send_msg_to_server(server_id, client, &req_lbm_msg, ret_msg); if (ret_status == TFS_ERROR) { NewClientManager::get_instance().destroy_client(client); return ret_status; } char* bit_data = NULL; int32_t map_len = 0, used_len = 0; if (RESP_LIST_BITMAP_MESSAGE == ret_msg->getPCode()) { RespListBitMapMessage* resp_lbm_msg = dynamic_cast<RespListBitMapMessage*> (ret_msg); map_len = resp_lbm_msg->get_length(); used_len = resp_lbm_msg->get_use_count(); bit_data = resp_lbm_msg->get_data(); ret_status = TFS_SUCCESS; } else { printf("get message type: %d\n", ret_msg->getPCode()); printf("get response message from dataserver failed.\n"); NewClientManager::get_instance().destroy_client(client); return TFS_ERROR; } print_bitmap(map_len, used_len, bit_data); NewClientManager::get_instance().destroy_client(client); return ret_status; }
static inline void send_fragment() { uint16_t frag_id; uint8_t i, j; uint8_t mask = 1; uint8_t ret; fetcher_fragment_t *out_pkt; fetcher_cam_t *cam; if ( send_state.map == NULL ) { ker_timer_stop(KER_FETCHER_PID, FETCHER_TRANSMIT_TID); return; } cam = (fetcher_cam_t *) ker_shm_get( KER_FETCHER_PID, send_state.map->key); if ( cam == NULL ) { // file got deleted. give up! free_send_state_map(); return; } if ( send_state.frag != NULL) { //! timer fires faster than data reading. Highly unlikely... //! but we still handle it. return; } //! search map and find one fragment to send for(i = 0; i < send_state.map->bitmap_size; i++) { //! for each byte if(send_state.map->bitmap[i] != 0) { break; } } if(i == send_state.map->bitmap_size) { /* * Did not find any block... */ free_send_state_map(); return; } //sos_assert(i < send_state.map->bitmap_size); frag_id = i * 8; mask = 1; for(j = 0; j < 8; j++, mask = mask << 1) { if(mask & (send_state.map->bitmap[i])) { send_state.map->bitmap[i] &= ~(mask); break; } } //sos_assert(j < 8); frag_id += j; print_bitmap(send_state.map); out_pkt = (fetcher_fragment_t*)ker_malloc(sizeof(fetcher_fragment_t), KER_FETCHER_PID); if(out_pkt == NULL){ DEBUG_PID(KER_FETCHER_PID,"malloc fetcher_fragment_t failed\n"); goto send_fragment_postproc; } out_pkt->frag_id = ehtons(frag_id); out_pkt->key = ehtons(send_state.map->key); ret = ker_codemem_read(cam->cm, KER_FETCHER_PID, out_pkt->fragment, FETCHER_FRAGMENT_SIZE, frag_id * (code_addr_t)FETCHER_FRAGMENT_SIZE); if(ret == SOS_SPLIT) { send_state.frag = out_pkt; } else if(ret != SOS_OK){ DEBUG_PID(KER_FETCHER_PID, "codemem_read failed\n"); ker_free(out_pkt); goto send_fragment_postproc; } //DEBUG("out_pkt has addr %x\n", (int)out_pkt); DEBUG_PID(KER_FETCHER_PID, "send_fragment: frag_id = %d to %d\n", frag_id, send_state.dest); ret = post_auto(KER_FETCHER_PID, KER_FETCHER_PID, MSG_FETCHER_FRAGMENT, sizeof(fetcher_fragment_t), out_pkt, SOS_MSG_RELEASE | SOS_MSG_RELIABLE, send_state.dest); if( ret == SOS_OK ) { send_state.num_msg_in_queue++; } send_fragment_postproc: if(check_map(send_state.map)) { //! no more fragment to send free_send_state_map(); } }
/* requires: that obj be an aligned pointer to an object, and next_index be the next index in the object that may need to be examined. returns: NO_POINTERS if there are no more pointers in the object, or 1+ the index of the next field or array index that contains a pointer. for arrays that contain fields, an array index is offset by the number of fields in the array. */ ptroff_t get_next_index(jobject_unwrapped obj, ptroff_t next_index) { int i, bits_needed, bitmaps_needed; ptroff_t *bitmap_ptr; // should only be called w/ aligned ptrs assert(obj == PTRMASK(obj)); // this object contains no pointers if (obj->claz->gc_info.bitmap == 0) { COLLECT_NOPTR_STATS(); return NO_POINTERS; } // we want to initialize i based on where we are in the object i = next_index/BITS_IN_GC_BITMAP; // we use one bit in the GC bitmap for each pointer-sized // word in the object. if the object size (including header) // is too big to be encoded in the in-line bitmap, then it's // put in the auxiliary bitmap, and the in-line field // contains a pointer to the bitmap bits_needed = (obj->claz->size + SIZEOF_VOID_P - 1)/SIZEOF_VOID_P; // if we are looking at the elements of the array, // we may not need to examine the bitmap at all if (obj->claz->component_claz != NULL) { struct aarray *arr = (struct aarray *)obj; // if we have already started examining array // elements, then the array must contain pointers if (next_index > bits_needed) { if (next_index < (arr->length + bits_needed)) return (INDEX_OFFSET + next_index); else return NO_POINTERS; } else // if we are going to look at the bitmap, we // need to remember that for arrays, we keep // an extra bit for the array elements bits_needed++; } bitmaps_needed = (bits_needed + BITS_IN_GC_BITMAP - 1)/BITS_IN_GC_BITMAP; assert(bitmaps_needed >= 0); if (bitmaps_needed > 1) { bitmap_ptr = obj->claz->gc_info.ptr; COLLECT_LRGOBJ_STATS(); } else bitmap_ptr = &(obj->claz->gc_info.bitmap); // after the first time around the outer loop, next_index // needs to be initialized relative to i for ( ; i < bitmaps_needed; i++, next_index = i*BITS_IN_GC_BITMAP) { ptroff_t bitmap = bitmap_ptr[i]; print_bitmap(bitmap); // if next_index is in the middle of a bitmap // we need to shift the bitmap over bitmap = bitmap >> (next_index - i*BITS_IN_GC_BITMAP); for ( ; bitmap != 0; next_index++) { // stop when we get to the first set bit if (bitmap & 1) { // need to check for zero-length arrays if (obj->claz->component_claz != NULL) { struct aarray *arr = (struct aarray *)obj; // check if we are looking at the last bit if (next_index == bits_needed - 1 && arr->length == 0) return NO_POINTERS; } return (INDEX_OFFSET + next_index); } // as we examine each bit in the bitmap, we // shift the bitmap right. bitmap = bitmap >> 1; } } // if we got this far, then we didn't find a pointer return NO_POINTERS; }
int main (int argc, char * argv[]){ long ncpus; double total_time; unsigned long long num_to_check; thread_info_t *thread_to_use; int thread_ret_val; if(argc != 2){ std::cout << "Please only enter the upper end range value\n"; return -1; } else{ upper_limit = (unsigned long long)atoll(argv[1]); sqrt_upper_limit = sqrtl(upper_limit); } if(upper_limit > pow(2, 32)){ std::cout << "Please keep the upper limit below 2^32\n"; } start = clock(); for(int i = 0; i < NUM_OF_THREADS; i++){ info[i].thread_index = i; info[i].marked_up_to = 3; info[i].thread_is_done = true; } bitmap = (unsigned long *)malloc(sizeof(unsigned long *) * upper_limit/8); for(unsigned long long i = 0; i < upper_limit/8; i++){ bitmap[i] = 0xAAAAAAAAAAAAAAAA; //wipe out evens } bitmap[0] = 0xCAAAAAAAAAAAAAAA; // go thru elements in array for(unsigned long long i = 0; i <= sqrt_upper_limit/bits_in_element; i++){ //go thru bits in elements for(unsigned long long j = (i == 0 ? 3 : 0); j < (bits_in_element > upper_limit ? upper_limit : bits_in_element) ; j++){ num_to_check = (i * bits_in_element) + j; //make sure all threads are past num_to_check for(int k = 0; ; k++){ if(k == NUM_OF_THREADS) k = 0; if(info[k].marked_up_to >= num_to_check) break; } //check if bit index is prime if(check_if_bit_index_is_prime(i, j)){ for(int k = 0; ; k++) {//wait for a finished thread to use if(k == NUM_OF_THREADS) k = 0; if(info[k].thread_is_done){ thread_to_use = &info[k]; info[k].thread_is_done = false; info[k].prime = (i * bits_in_element) + j; break; } } //thread gets rid of multiples thread_ret_val = pthread_create(&thread_to_use->thread, NULL, threadFunc, (void *)thread_to_use); if(thread_ret_val != 0){ std::cerr << "thread error: " << strerror(thread_ret_val) << "\n"; return -1; } } } } for(int i = 0; i < NUM_OF_THREADS; i++){ thread_ret_val = pthread_join(info[i].thread, NULL); if(thread_ret_val != 0){ std::cerr << strerror(thread_ret_val); } } stop = clock(); total_time = (double)(stop - start) / (double)CLOCKS_PER_SEC; ncpus = sysconf(_SC_NPROCESSORS_ONLN); /* Print performance results */ printf ("Total time using %d threads : %.6f seconds\n", NUM_OF_THREADS, total_time / (NUM_OF_THREADS < ncpus ? NUM_OF_THREADS : ncpus)); print_bitmap(); free(bitmap); return 1; }
void dump_action_capabilities( const action_capabilities capabilities ) { print_bitmap( capabilities, ACTION_OUTPUT, "output" ); print_bitmap( capabilities, ACTION_COPY_TTL_OUT, "copy_ttl_out" ); print_bitmap( capabilities, ACTION_COPY_TTL_IN, "copy_ttl_in" ); print_bitmap( capabilities, ACTION_SET_MPLS_TTL, "set_mpls_ttl" ); print_bitmap( capabilities, ACTION_DEC_MPLS_TTL, "dec_mpls_ttl" ); print_bitmap( capabilities, ACTION_PUSH_VLAN, "push_vlan" ); print_bitmap( capabilities, ACTION_POP_VLAN, "pop_vlan" ); print_bitmap( capabilities, ACTION_PUSH_MPLS, "push_mpls" ); print_bitmap( capabilities, ACTION_POP_MPLS, "pop_mpls" ); print_bitmap( capabilities, ACTION_SET_QUEUE, "set_queue" ); print_bitmap( capabilities, ACTION_GROUP, "group" ); print_bitmap( capabilities, ACTION_SET_NW_TTL, "set_nw_ttl" ); print_bitmap( capabilities, ACTION_DEC_NW_TTL, "dec_nw_ttl" ); print_bitmap( capabilities, ACTION_SET_FIELD, "set_field" ); print_bitmap( capabilities, ACTION_PUSH_PBB, "push_pbb" ); print_bitmap( capabilities, ACTION_POP_PBB, "pop_pbb" ); print_bitmap( capabilities, ACTION_EXPERIMENTER, "experimenter" ); }
int decode_sc_data(struct loco_config_t *loco_config, struct loco_data_t *loco_data) { unsigned int i, j, k, func, id, temp, png_size; unsigned char index, length; char *loco_name; char *proto_name; char *png_name; index = 0; /* preamble */ if (memcmp(loco_config->bin, pre_mfx, 3) == 0) printf("type: mfx\n"); else if (memcmp(loco_config->bin, pre_mm, 3) == 0) printf("type: mm\n"); else if (memcmp(loco_config->bin, pre_other, 3) == 0) printf("type: other\n"); else return EXIT_FAILURE; i = 3; while (i < loco_config->eeprom_size) { index = loco_config->bin[i++]; length = loco_config->bin[i++]; switch (index) { case 0: printf("index [0x%02x @ 0x%04x] sub-index [%u]: ", index, i, length); temp = loco_config->bin[i++]; length = (loco_config->bin[i++] << 8) + temp; printf(" total length [%u]\n", length); id = loco_config->bin[i++]; while ((id != 0) && (id != 255)) { length = loco_config->bin[i++]; /* printf("i 0x%02x [i] 0x%02x length %u\n" , i, loco_config->bin[i], length); */ switch (id) { case 0x1e: loco_name = extract_string(&i, loco_config->bin, length); if (loco_name == NULL) return EXIT_FAILURE; loco_data->name = loco_name; printf("loco name: >%s<\n", loco_name); break; case 0x1f: proto_name = extract_string(&i, loco_config->bin, length); if (proto_name == NULL) return EXIT_FAILURE; printf("proto name: >%s<\n", proto_name); loco_data->type = proto_name; break; case 0x20: png_name = extract_string(&i, loco_config->bin, length); if (png_name == NULL) return EXIT_FAILURE; printf("png name: >%s<\n", png_name); loco_data->icon = png_name; break; case 0x05: png_size = length + (loco_config->bin[i++] << 8); printf("png start: 0x%04x end: 0x%04x size: 0x%04x %u bytes\n", i, i + png_size, png_size, png_size); return EXIT_SUCCESS; default: printf("decoding problem: 0x%02x\n", id); break; } id = loco_config->bin[i++]; if (id == 0) id = loco_config->bin[i++]; } break; /* Loco functions */ case 9: printf("index [0x%02x @ 0x%04x] length [%3d]: ", index, i, length); func = 0; printf("\n"); for (j = 0; j < length / 10; j++) { printf(" function %2u: ", func++); for (k = 0; k < 10; k++) { printf(" 0x%02x", loco_config->bin[i++]); } printf("\n"); i -= 10; for (k = 0; k < 10; k++) { uint8_t ti = loco_config->bin[i++]; switch(k) { case 0: printf(" %10s 0x%02x", loco_function_string[ti & 0x07], ti); break; case 99: /* TODO */ printf("\n"); print_bitmap(&loco_config->bin[i]); break; default: break; } } printf("\n"); } break; default: printf("index [0x%02x @ 0x%04x] length [%3d]: ", index, i, length); if (length <= 4) memcpy(&temp, loco_config->bin, length); else temp = 0; switch (index) { case 1: loco_data->long_uid = temp; printf(" mfx UID "); break; case 2: loco_data->uid = temp; printf(" UID "); break; case 3: loco_data->acc_delay = temp; printf("acceleration delay "); break; case 4: loco_data->slow_down_delay = temp; printf(" slow down delay "); break; case 5: loco_data->vmin = temp; printf(" Vmin "); break; case 6: loco_data->vmax = temp; printf(" Vmax "); break; case 7: loco_data->tacho = temp; printf(" tacho "); break; case 8: loco_data->volume = temp; printf(" volume "); break; default: printf(" unknown "); break; } for (j = 0; j < length; j++) { printf(" 0x%02x", loco_config->bin[i++]); } break; } printf("\n"); if (index == 0) break; } return 0; }