void update_slice_hist(void) { int i; for(i=0; i<nsliceinfo; i++) { slice *slicei; int unit1; FILE_SIZE lenfile; int error1; float slicetime1, *sliceframe; int sliceframesize; int is1, is2, js1, js2, ks1, ks2; int testslice; slicei = sliceinfo + i; LOCK_SLICE_BOUND; if(slicei->inuse_getbounds==1) { UNLOCK_SLICE_BOUND; continue; } slicei->inuse_getbounds=1; UNLOCK_SLICE_BOUND; PRINTF(" Examining %s\n",slicei->file); lenfile=strlen(slicei->file); LOCK_COMPRESS; FORTget_file_unit(&unit1,&slicei->unit_start); FORTopenslice(slicei->file,&unit1,&is1,&is2,&js1,&js2,&ks1,&ks2,&error1,lenfile); UNLOCK_COMPRESS; sliceframesize=(is2+1-is1)*(js2+1-js1)*(ks2+1-ks1); NewMemory((void **)&sliceframe,sliceframesize*sizeof(float)); init_histogram(slicei->histogram); testslice=0; while(error1==0) { FORTgetsliceframe(&unit1, &is1, &is2, &js1, &js2, &ks1, &ks2, &slicetime1, sliceframe, &testslice,&error1); update_histogram(sliceframe,sliceframesize,slicei->histogram); } FREEMEMORY(sliceframe); LOCK_COMPRESS; FORTclosefortranfile(&unit1); UNLOCK_COMPRESS; } }
int main(int argc, char** argv) { struct kuhler_data kd1; kd1.usb_mode_control_packet[silent] = (char[0x20]) silent_mode_control; kd1.usb_mode_control_packet[extreme] = (char[0x20]) extreme_mode_control; kd1.usb_mode_control_packet[custom] = (char[0x20]) custom_mode_control; kd1.usb_status_packet[silent] = (char[0x20]) silent_status_control; kd1.usb_status_packet[extreme] = (char[0x20]) extreme_status_control; kd1.usb_status_packet[custom] = (char[0x20]) custom_status_control; // MUTEX Lock pthread_mutex_init(&kuhler_mutex,NULL); int c; int debug_level; int update_thread_enable = 1; while ((c = getopt(argc,argv,"d:hn")) != -1) { switch (c) { case 'h' : printargs(); exit(0); break; case 'd' : debug_level = 1; break; case 'n' : update_thread_enable = 0; break; default : debug_level = 0; } } // Init Log Factiity // EMERG,ALRT,CRIT,ERR,WARNING,NOTICE,INFO,DEBUG if (debug_level == 1) { setlogmask (LOG_UPTO(LOG_DEBUG)); printf ("Debug Mode Enabled!\n"); } else { setlogmask (LOG_UPTO(LOG_NOTICE)); } openlog ("kuhlerd", LOG_CONS | LOG_PID | LOG_NDELAY , LOG_LOCAL1); syslog (LOG_NOTICE, "kuhlerd version %s Started",version_string); // Init kd_ptr kd_ptr = &kd1; struct control_packet cp; struct status_packet sp; shm_id_cp = shmget(shm_key_cp,sizeof(cp),IPC_CREAT | 0666); //rw-,rw-,rw- shm_id_sp = shmget(shm_key_sp,sizeof(sp),IPC_CREAT | 0666); //rw,r--,r-- if (shm_id_cp < 0 || shm_id_sp < 0) { syslog (LOG_ERR, "Failed to Allocate Shared Memory Segment \n"); printf ("Kuhlerd : Failed to Allocate Shared Memory Segment\n"); exit(1); } syslog (LOG_DEBUG, "Allocated Shared Memory Segment %d %d \n", shm_id_sp,shm_id_cp); cp_ptr = shmat(shm_id_cp,NULL,0); sp_ptr = shmat(shm_id_sp,NULL,0); if (cp_ptr == NULL || sp_ptr == NULL) { syslog (LOG_ERR, "Failed to Attach to Shared Memory Segment \n"); printf ("Kuhlerd : Failed to Attach Shared Memory Segment\n"); exit(1); } int r = 1; r = libusb_init(NULL); if (r < 0) { syslog (LOG_ERR, "Failed to Initialized libusb \n"); fprintf(stderr, "Kuhlerd : failed to initialise libusb\n"); exit(1); } r = find_kuhler920(); if (r < 0) { syslog (LOG_ERR, "Could not find Kuhler 920/960 or open device \n"); fprintf(stderr, "Kuhlerd : Could not find/open device\n"); exit(1); } r = libusb_claim_interface(devh, 0); if (r < 0) { syslog (LOG_ERR, "Could not claim exclusive use of usb device \n"); fprintf(stderr, "Kuhlerd : usb_claim_interface error %d\n", r); exit(1); } syslog (LOG_DEBUG,"Claimed Interface \n"); printf("Kuhlerd : claimed interface\n"); syslog (LOG_DEBUG,"Sending Init Packet\n"); printf("Kuhlerd : Sending Init Packet\n"); r = init_kuhler920(); syslog (LOG_DEBUG,"Init Packet Sent, returned with status %d \n",r); printf("Kuhlerd : Init Packet Sent, returned with status %d \n",r); //init_signals(); syslog (LOG_DEBUG,"Creating Histogram Entries %d \n",r); init_histogram(sp_ptr); syslog (LOG_DEBUG,"Created Histogram Entries %d \n",r); int i=0; int current_mode = silent; cp_sem = sem_open(cp_sem_name, O_CREAT , 0666,0); // 1 = unlocked , 0 = locked sp_sem = sem_open(sp_sem_name, O_CREAT , 0666,0); // 1 = unlocked , 0 = locked // v0.5 -- HW BUSY Semaphore - IPC kuhler_hw_busy_sem = sem_open(kuhler_hw_busy_sem_name,O_CREAT,0666,0); //if (cp_sem == NULL || sp_sem == NULL) { if (cp_sem == NULL || sp_sem == NULL || kuhler_hw_busy_sem == NULL) { syslog (LOG_ERR, "Failed to Create semaphores \n"); printf ("Kuhlerd : failed to create semaphores\n"); exit(1); } // Initialize Shared Memory For Safety cp_ptr->mode = silent; cp_ptr->cmd = 0; cp_ptr->led_r = (uint8_t) 0; cp_ptr->led_g = (uint8_t) 0; cp_ptr->led_b = (uint8_t) 0; cp_ptr->start_temp = 40; cp_ptr->full_temp = 55; change_mode(silent,kd_ptr); get_status_packet(sp_ptr); syslog (LOG_NOTICE, "Entering Main Loop\n"); printf ("Kuhlerd : Entering Main Loop\n"); int rv=-99; // Fork Off and Exit pid_t pidd; pidd = fork(); //if (pidd == 0) { init_signals(); // create pthreads pthread_t upd; // new for V5 - update thread if (update_thread_enable == 1) { int pthread_val = pthread_create(&upd,NULL,update_thread,NULL); syslog(LOG_NOTICE, "Creating Update Thread \n"); printf ("Kuhlerd : Creating Update Thread \n"); } else { syslog(LOG_NOTICE, "Update thread disabled \n"); printf ("Kuhlerd : Disabling Update Thread \n"); } if (pidd !=0) { syslog(LOG_NOTICE, "Entering Daemon Mode, exiting \n"); printf ("Kuhlerd : Entering Daemon Mode, exiting \n"); exit (0); } while (i==0) { // wait for the semaphore to be unlocked - written to 1 by ctl program //printf ("Waiting for Semaphore Unlock %i\n",rv); // hw busy control semaphore initially LOCKED sem_post(kuhler_hw_busy_sem); rv = sem_wait(cp_sem); // set to 0 -- blocking call // hw busy control semaphore initially LOCKED //sem_post(kuhler_hw_busy_sem); if (cp_ptr->cmd == 1 ) { change_led_color(cp_ptr->led_r,cp_ptr->led_g,cp_ptr->led_b,cp_ptr->mode,kd_ptr); if (cp_ptr->mode == custom) { change_temp_threshold(cp_ptr->start_temp,cp_ptr->full_temp,kd_ptr); } change_mode(cp_ptr->mode,kd_ptr); get_status_packet(sp_ptr); // required after mode change } else { send_status_packet(cp_ptr->mode,kd_ptr); sleep(1); get_status_packet(sp_ptr); // unlock status packet semaphore sem_post(sp_sem); } } // end while }
void mpiPi_init (char *appName) { if (time (&mpiPi.start_timeofday) == (time_t) - 1) { mpiPi_msg_warn ("Could not get time of day from time()\n"); } mpiPi.toolname = "mpiP"; mpiPi.comm = MPI_COMM_WORLD; mpiPi.tag = 9821; mpiPi.procID = getpid (); mpiPi.appName = strdup (appName); PMPI_Comm_rank (mpiPi.comm, &mpiPi.rank); PMPI_Comm_size (mpiPi.comm, &mpiPi.size); PMPI_Get_processor_name (mpiPi.hostname, &mpiPi.hostnamelen); mpiPi.stdout_ = stdout; mpiPi.stderr_ = stderr; mpiPi.lookup = mpiPi_lookup; mpiPi.enabled = 1; mpiPi.enabledCount = 1; mpiPi.cumulativeTime = 0.0; mpiPi.global_app_time = 0.0; mpiPi.global_mpi_time = 0.0; mpiPi.global_mpi_size = 0.0; mpiPi.global_mpi_io = 0.0; mpiPi.global_mpi_rma = 0.0; mpiPi.global_mpi_msize_threshold_count = 0; mpiPi.global_mpi_sent_count = 0; mpiPi.global_time_callsite_count = 0; mpiPi.global_task_hostnames = NULL; mpiPi.global_task_app_time = NULL; mpiPi.global_task_mpi_time = NULL; /* set some defaults values */ mpiPi.collectorRank = 0; mpiPi.tableSize = 256; mpiPi.reportPrintThreshold = 0.0; mpiPi.baseNames = 0; mpiPi.reportFormat = MPIP_REPORT_SCI_FORMAT; mpiPi.calcCOV = 1; mpiPi.inAPIrtb = 0; mpiPi.do_lookup = 1; mpiPi.messageCountThreshold = -1; if (DEFAULT_REPORT_FORMAT == mpiPi_style_concise) { mpiPi.report_style = mpiPi_style_concise; mpiPi.stackDepth = 0; mpiPi.print_callsite_detail = 0; } else // verbose default { mpiPi.report_style = mpiPi_style_verbose; mpiPi.stackDepth = 1; mpiPi.print_callsite_detail = 1; } #ifdef COLLECTIVE_REPORT_DEFAULT mpiPi.collective_report = 1; #else mpiPi.collective_report = 0; #endif mpiPi.disable_finalize_report = 0; mpiPi.do_collective_stats_report = 0; mpiPi.do_pt2pt_stats_report = 0; #ifdef SO_LOOKUP mpiPi.so_info = NULL; #endif mpiPi.do_pt2pt_detail_report = 0; mpiPi_getenv (); mpiPi.task_callsite_stats = h_open (mpiPi.tableSize, mpiPi_callsite_stats_pc_hashkey, mpiPi_callsite_stats_pc_comparator); mpiPi.accumulatedPt2ptCounts = NULL; mpiPi.accumulatedPt2ptData = NULL; if (mpiPi.do_collective_stats_report == 1) { init_histogram (&mpiPi.coll_comm_histogram, 7, 32, NULL); init_histogram (&mpiPi.coll_size_histogram, 7, 32, NULL); } if (mpiPi.do_pt2pt_stats_report == 1) { init_histogram (&mpiPi.pt2pt_comm_histogram, 7, 32, NULL); init_histogram (&mpiPi.pt2pt_size_histogram, 7, 32, NULL); if(mpiPi.do_pt2pt_detail_report == 1) { mpiPi.task_pt2pt_stats = h_open(mpiPi.tableSize, mpiPi_pt2pt_stats_rank_hashkey, mpiPi_pt2pt_stats_rank_comparator); } } /* -- welcome msg only collector */ if (mpiPi.collectorRank == mpiPi.rank) { mpiPi_msg (""); mpiPi_msg ("%s V%d.%d.%d (Build %s/%s)\n", mpiPi.toolname, mpiPi_vmajor, mpiPi_vminor, mpiPi_vpatch, mpiPi_vdate, mpiPi_vtime); mpiPi_msg ("Direct questions and errors to %s\n", MPIP_HELP_LIST); mpiPi_msg ("\n"); } mpiPi_msg_debug ("appName is %s\n", appName); mpiPi_msg_debug ("sizeof(callsite_stats_t) is %d\n", sizeof (callsite_stats_t)); mpiPi_msg_debug ("successful init on %d, %s\n", mpiPi.rank, mpiPi.hostname); if (mpiPi.enabled) { mpiPi_GETTIME (&mpiPi.startTime); } return; }