Example #1
0
void Detection::WorkFunc()
{
    CheckIP138();
    CheckIP();
    TestTinydrag();
    Ping();
    GetLocalIP();
    Test9KAPPPAC();
    Test9K();
    Test8888();
    boost::thread work_thread(boost::bind(&Detection::TestTracker, this));
    for (int i = 0; i < 5 * 60; ++i)
    {
        if (i % 3 == 0)
        {
            ++m_progress_pos_;
            if (i % 60 == 0)
            {
                Test9K();
            }
        }
        Sleep(1000);
    }
    Analyze();
    TestBs();
    Test9K();
    WriteTrackerResult();
    Sleep(1000);
    MessageBox("测试完毕!");
}
Example #2
0
int main (int argc, char *argv[])
{
    int c, i, j;
    int begin, end;
    int iTotalSize;
    pthread_attr_t attr;
    pthread_t *tid;
    int *id;
    double error;
    if (argc == 1)
    {
	printf("This program should take at least one parameter for input matrix\n");
	return 0;
    }
    if (argc == 3)
	task_num = atoi(argv[2]);
    if (argc > 3)
    {
	printf("This program should not take more than 2 parameters \n");
	return 0;
    }
    nsize = initMatrix(argv[1]);
    id = (int *) malloc (sizeof (int) * task_num);
    tid = (pthread_t *) malloc (sizeof (pthread_t) * task_num);
    if (!id || !tid)
    {
	fprintf(stderr, "The matrix file open error\n");
        exit(-1);
    }
    pthread_attr_init (&attr);
    pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM);
    for (i = 1; i < task_num; i++) {
        id[i] = i;
        pthread_create (&tid[i], &attr, work_thread, &id[i]);
    }
    id[0]=0;
    work_thread(&id[0]);
    // wait for all threads to finish
    for (i = 1; i < task_num; i++)
        pthread_join (tid[i], NULL);

    FILE *result;
    result = fopen ("result.txt", "w");
    for (i=0; i<nsize; i++){
        fprintf (result, "X[%d] = %f \n", i, X[i]);
    }
    error = 0.0;

    for (i = 0; i < nsize; i++) {
        double error__ = (X__[i]==0.0) ? 1.0 : fabs((X[i]-X__[i])/X__[i]);
        if (error < error__) {
            error = error__;
        }
    }
    fprintf(stdout, "Error: %6.3f\n", error);
    return 0;
}
int main(int argc, char *argv[])
{
    int i;
    struct timeval start, finish;
    double error;
    
    pthread_attr_t attr;
    pthread_t *tid;
    int *id;
    
    if (argc < 2) {
	fprintf(stderr, "usage: %s <matrixfile>\n", argv[0]);
	exit(-1);
    }
    
    // for getting the threads
    if(argc == 3) {
        task_num = strtol(argv[2], NULL, 10);
    }

    nsize = initMatrix(argv[1]);
    initRHS(nsize);
    initResult(nsize);
   
    // create threads
    id = (int *) malloc (sizeof (int) * task_num);
    tid = (pthread_t *) malloc (sizeof (pthread_t) * task_num);
    if (!id || !tid)
        errexit ("out of shared memory");
    pthread_attr_init (&attr);
    pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM);
    for (i = 1; i < task_num; i++) {
        id[i] = i;
        pthread_create (&tid[i], &attr, work_thread, &id[i]);
    }

    id[0]=0;
    work_thread(&id[0]);
    // wait for all threads to finish
    for (i = 1; i < task_num; i++)
        pthread_join (tid[i], NULL);
	    
    solveGauss(nsize);
    
    error = 0.0;
    for (i = 0; i < nsize; i++) {
	double error__ = (X__[i]==0.0) ? 1.0 : fabs((X[i]-X__[i])/X__[i]);
	if (error < error__) {
		error = error__;
	}
    }
    fprintf(stdout, "Error: %e\n", error);
}
Example #4
0
void Detection::OnBnClickedButtonDetStart()
{
    // TODO: Add your control notification handler code here
    // 首先结束掉所有PPLive进程
    //m_p2p_monitor_dlg->OnBnClickedKillAll();

    memset(&ShExecInfo, 0, sizeof(ShExecInfo));
    ShExecInfo.cbSize =  sizeof(SHELLEXECUTEINFO);
    ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
    ShExecInfo.hwnd = NULL;
    ShExecInfo.lpVerb = NULL;
    ShExecInfo.lpFile = _T("cmd");
    ShExecInfo.lpDirectory = _T(" C:\ ");
    ShExecInfo.nShow = SW_HIDE;
    ShExecInfo.hInstApp = NULL;

    m_progress_control.SetRange32(0, 159);

    std::ofstream fout("text.txt");
    fout << "开始检测,检测时间:";
    time_t t = time(0);
    char tmp[64];
    strftime(tmp, 64, "%X", localtime(&t));
    for(int i = 0; i < strlen(tmp); ++i)
    {
        fout << tmp[i];
    }
    fout << std::endl;
    fout.close();

    // 保存当前路径
    char current_dir[512];
    GetCurrentDirectory(512, current_dir);

//     m_p2p_monitor_dlg->OnBnClickedRunPpap();
//     m_p2p_monitor_dlg->OnBnClickedRunPplive();

    ::MessageBox(this->m_hWnd, "请在PPTV客户端中双击一个节目,双击完了之后点确定按钮", "Title", MB_OK);
    SetCurrentDirectory(current_dir);

    m_p2p_monitor_dlg->m_p2p_dlg->SetSaving(TRUE);
    m_p2p_monitor_dlg->m_p2p_dlg->SetStart();

    IniTrachkerList();

    boost::thread work_thread(boost::bind(&Detection::WorkFunc, this));
    boost::thread draw_thread(boost::bind(&Detection::DrawProcessControl, this));
}
void pthread_render(image_info_t *info, worker_task_t *task) {
    pthread_t
    *worker_threads;
    pthread_attr_t
    attr;
    unsigned long
    i;
    worker_argument_t
    argument;

    argument.task = task;
    argument.info = info;

    worker_threads = malloc(sizeof(pthread_t) * ( num_threads - 1 ));
    if(worker_threads == NULL) {
        perror(PROG_NAME);
        exit(3);
    }

    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);

    progress = task->y_start;

    /* Creating threads */
    for(i = 0; i < (num_threads - 1); i++) {
        pthread_create(&worker_threads[i], &attr, work_thread, (void *)&argument);
    }

    work_thread((void *)&argument);

    /* Waiting for other threads to die */
    for(i = 0; i < (num_threads - 1); i++) {
        pthread_join(worker_threads[i], NULL);
    }

    free(worker_threads);
}
int main(int argc,char *argv[])
{
    int i;
    pthread_t *tid;
    int *id;
    
    double mhz;
    hrtime_t hrcycle1, hrcycle2;

    while((i = getopt(argc,argv,"s:p:")) != -1){
        switch(i){
            case 's':
                {
                    int s;
                    s = atoi(optarg);
                    if (s > 0){
                        nsize = s;
                    } else {
                        fprintf(stderr,"Entered size is negative, hence using the default (%d)\n",(int)NSIZE);
                    }
                }
                break;
            case 'p':
                {
                    int p;
                    p = atoi(optarg);
                    if (p > 0){
                        task_num = p;
                    } else {
                        fprintf(stderr,"Entered task number is negative, hence using the default value: 1\n");
                    }
                }
                break;
            default:
                assert(0);
                break;
        }
    }
    
#ifdef CHECK_CORRECTNESS
    nsize = 3;
    allocate_memory(nsize);
    initCheck(nsize);
#else
    allocate_memory(nsize);
    initMatrix(nsize);
#endif
    
    hrcycle1 = gethrcycle_x86();
/* create thread*/
    id = (int *) malloc (sizeof (int) * task_num);
    tid = (pthread_t *) malloc (sizeof (pthread_t *) * task_num);
    if (!id || !tid)
        errexit ("out of shared memory");


    for(i=1; i<task_num; i++){
        id[i] = i;
        pthread_create(&tid[i], NULL, work_thread, &id[i]);
    }

    id[0] = 0;
    work_thread(&id[0]);

    for(i=1; i<task_num; i++){
        pthread_join(tid[i], NULL);
    }

#if VERIFY
    solveGauss(nsize);
#endif

    hrcycle2 = gethrcycle_x86();
    mhz = getMHZ_x86();

    printf("Here hrcycle = %lld, mhz = %f HZ\n", hrcycle2 - hrcycle1, mhz);


#if VERIFY
    for(i = 0; i < nsize; i++)
        printf("%6.5f %5.5f\n",B[i],C[i]);
#endif
    
    return 0;
}
Example #7
0
/* This program stress-tests the cpu by running a very tight Gromacs innerloop. */
int
main(int argc, char **argv)
{
    int                    nthreads,ncpu;
    int                    help;
    int                    silent;
    int                    i,rc;
    int                    hours,minutes,seconds;
    time_t                 finish;
    common_data_t          common_data;
    thread_data_t *        thread_data;
    int                    x8664;
    void *                 ret;

#ifdef HAVE_SYSCTL
    ncpu = detect_ncpus_sysctl();
#elif defined _WIN32
    ncpu = detect_ncpus_windows();
#else
    ncpu = detect_ncpus_linux();
#endif

    if(ncpu<1)
    {
        ncpu = 1;
    }

    nthreads = ncpu;
    help     = 0;
    silent   = 0;
    hours    = 99999;
    minutes  = 59;
    seconds  = 59;
    
    

    if(argc>1)
    {
        for(i=1;i<argc;i++) 
        {
            if(strlen(argv[i])>1 && !strncmp(argv[i],"-h",2))
            {
                help=1;
            }
            if(strlen(argv[i])>1 && !strncmp(argv[i],"-s",2))
            {
                silent=1;
            }
#ifndef NO_THREADS
            if(i<argc-1 && strlen(argv[i])>1 && !strncmp(argv[i],"-n",2)) 
            {
                /* n flag given, and there is another argument that could be number of threads */
                nthreads=strtol(argv[i+1],NULL,10);
            }            
#endif
            if(i<argc-1 && strlen(argv[i])>1 && !strncmp(argv[i],"-t",2)) 
            {
                /* Read time in hh:mm:ss from next argument */
                parse_time(argv[i+1],&hours,&minutes,&seconds);
            }
        }
    }
    finish = time(NULL) + (hours*60+minutes)*60+seconds;
    common_data.timed = (hours<99999) ? 1 : 0;

    if (silent==0)
    {
        printf("\nCPU stress tester 2.0 (-h for help)\n");
#ifdef __x86_64__
        printf("Architecture: x86-64/EM64t (64bit)\n");
#else
        printf("Architecture: ia32/x86 (32bit)\n");
#endif
        printf("Copyright (c) Erik Lindahl <*****@*****.**> 2004-2007\n");

        if (help==1)
        {
            printf("\nThis program accomplishes two things:\n\n");
            printf("1. It heats your CPU by running hand-tuned SSE assembly\n");
            printf("2. It checks the results to find memory and similar subtle errors\n\n");
            printf("The actual code is a custom version of the GROMACS assembly loops.\n");
            printf("Check out http://www.gromacs.org for details.\n\n");
            
            printf("Available options:\n");
            printf(" -h            Print this help message.\n");
            printf(" -s            Completely silent execution (only print errors)\n");
#ifndef NO_THREADS
            printf(" -n #          Set # threads manually instead of automatically\n");
#endif
            printf(" -t hh:mm:ss   Runtime\n\n");
            printf("If an error occurs, executions stops with a string including 'ERROR'.\n\n");        
            
            printf("This program is free software; you can redistribute it and/or\n");
            printf("modify it under the terms of the GNU General Public License\n");
            printf("as published by the Free Software Foundation; either version 2\n");
            printf("of the License, or (at your option) any later version.\n");
            printf("Other usage is normally fine too, contact the author for permission.\n\n");
            exit(0);
        }
  
		printf("Found %d CPU%s. (-n overrides #threads)\n",ncpu,(ncpu>1) ? "s" : "");
        if(common_data.timed)
        {    
            printf("Executing %d thread%s for %dh %dm %ds - will finish %s",
                   nthreads, (nthreads>1) ? "s" : "", hours,minutes,seconds,ctime(&finish));
        }
        else
        {
            printf("Executing %d thread%s indefinitely.\n",nthreads, (nthreads>1) ? "s" : "");
        }
    }
    
    common_data.thread_data = malloc(sizeof(thread_data_t)*nthreads);
    common_data.nthreads    = nthreads;
    common_data.silent      = silent;
    common_data.iter        = 0;
    common_data.finish      = finish;
    

#ifdef NO_THREADS
    thread_data = &common_data.thread_data[0];
    thread_data->threadid=0;
    thread_data->common=&common_data; /* back pointer */
    work_thread(thread_data);
#else
    stresscpu_thread_mutex_init(&common_data.mtx);
    for(i=0;i<nthreads;i++)
    {
        thread_data = &common_data.thread_data[i];
        thread_data->threadid=i;
        thread_data->common=&common_data; /* back pointer */
        
        
        rc=stresscpu_thread_create(&thread_data->thread,
                                   work_thread,
                                   thread_data);
        if(rc!=0)
        {
            printf("\nERROR: System cannot start threads. Exiting.\n");
            exit(1);
        }
    }
    
    for(i=0;i<nthreads;i++)
    {
        stresscpu_thread_join(common_data.thread_data[i].thread,
                              &ret);
    }
#endif
    
    if(silent==0)
    {
        printf("\nNo problems detected, clean exit.\n");
    }
    

    return 0;
}
Example #8
0
int main(int argc, char *argv[])
{
    int i;
    struct timeval start, finish;
    double error;

    pthread_attr_t attr;
    pthread_t *tid;
    int *id;
    
    //Ensure that the program takes two parameters
    //  first param is the input matrix and the second is the number of processors for the parallel run    
    if (argc != 3) {
        fprintf(stderr, "usage: %s <matrixfile> <#ofProcesses>\n", argv[0]);
        exit(-1);
    }

    task_num = atoi(argv[2]);
    nsize = initMatrix(argv[1]);
    initRHS(nsize);
    initResult(nsize);

    gettimeofday(&start, 0);

    // create threads
    id = (int *) malloc (sizeof (int) * task_num);
    tid = (pthread_t *) malloc (sizeof (pthread_t) * task_num);
    if (!id || !tid)
        errexit ("out of shared memory");
    pthread_attr_init (&attr);
    pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM);
    for (i = 1; i < task_num; i++) {
        id[i] = i;
        pthread_create (&tid[i], &attr, work_thread, &id[i]);
    }

    id[0]=0;
    work_thread(&id[0]);
    // wait for all threads to finish
    for (i = 1; i < task_num; i++)
        pthread_join (tid[i], NULL);

    gettimeofday(&finish, 0);

    solveGauss(nsize);

    fprintf(stdout, "Time:  %f seconds\n", (finish.tv_sec - start.tv_sec) + (finish.tv_usec - start.tv_usec)*0.000001);

    
    error = 0.0;
    for (i = 0; i < nsize; i++) {
    double error__ = (X__[i]==0.0) ? 1.0 : fabs((X[i]-X__[i])/X__[i]);
    if (error < error__) {
        error = error__;
    }
    }
    fprintf(stdout, "Error: %e\n", error);


    //File output
    // float timeOutput = ((finish.tv_sec - start.tv_sec) + (finish.tv_usec - start.tv_usec)*0.000001);

    // FILE *pthreadTimingFile = fopen("pthread1Timing.txt", "a");
    // fprintf(pthreadTimingFile, "%s %d %f %G\n", argv[1], task_num, timeOutput, error);
    // fclose(pthreadTimingFile);

    return 0;
}