コード例 #1
0
void init_monitor_mode(struct vegas_thread_args *args, int *nthread) {
    vegas_thread_args_init(&args[0]); // net
    vegas_thread_args_init(&args[1]); // null
    args[0].output_buffer = 1;
    args[1].input_buffer = args[0].output_buffer;
    *nthread = 2;
}
コード例 #2
0
void init_hbw_mode(struct vegas_thread_args *args, int *nthread) {
    vegas_thread_args_init(&args[0]); // net
    vegas_thread_args_init(&args[1]); // accum
    args[0].output_buffer = 2;
    args[1].input_buffer = args[0].output_buffer;
    args[1].output_buffer = 3;
    *nthread = 2;
}
コード例 #3
0
ファイル: test_net_thread.c プロジェクト: andriu5/vegas_devel
int main(int argc, char *argv[]) {

    static struct option long_opts[] = {
        {"help",    0, NULL, 'h'},
        {"disk",    0, NULL, 'd'},
        {"only_net",0, NULL, 'o'},
        {0,0,0,0}
    };
    int opt, opti;
    int disk=0, only_net=0;
    while ((opt=getopt_long(argc,argv,"hdo",long_opts,&opti))!=-1) {
        switch (opt) {
            case 'd':
                disk=1;
                break;
            case 'o':
                only_net=1;
                break;
            default:
            case 'h':
                usage();
                exit(0);
                break;
        }
    }

    /* Net thread args */
    struct vegas_thread_args net_args;
    vegas_thread_args_init(&net_args);
    net_args.output_buffer = 1;

    /* Init shared mem */
    struct vegas_status stat;
    struct vegas_databuf *dbuf=NULL;
    int rv = vegas_status_attach(&stat);
    if (rv!=VEGAS_OK) {
        fprintf(stderr, "Error connecting to vegas_status\n");
        exit(1);
    }
    dbuf = vegas_databuf_attach(net_args.output_buffer);
    /* If attach fails, first try to create the databuf */
    if (dbuf==NULL) 
#ifdef NEW_GBT
        dbuf = vegas_databuf_create(24, 32*1024*1024, net_args.output_buffer, CPU_INPUT_BUF);
#else
        dbuf = vegas_databuf_create(24, 32*1024*1024, net_args.output_buffer);
#endif
     /* If that also fails, exit */
    if (dbuf==NULL) {
        fprintf(stderr, "Error connecting to vegas_databuf\n");
        exit(1);
    }
    vegas_databuf_clear(dbuf);

    run=1;
    signal(SIGINT, cc);

    /* Launch net thread */
    pthread_t net_thread_id;
    rv = pthread_create(&net_thread_id, NULL, vegas_net_thread,
            (void *)&net_args);
    if (rv) { 
        fprintf(stderr, "Error creating net thread.\n");
        perror("pthread_create");
        exit(1);
    }

    /* Launch raw disk (or null) thread */
    struct vegas_thread_args null_args;
    vegas_thread_args_init(&null_args);
    null_args.input_buffer = net_args.output_buffer;
    pthread_t disk_thread_id=0;
    if (only_net==0) {
        if (disk)
            rv = pthread_create(&disk_thread_id, NULL, vegas_rawdisk_thread, 
                    (void *)&null_args);
        else
            rv = pthread_create(&disk_thread_id, NULL, vegas_null_thread, 
                    (void *)&null_args);
        if (rv) { 
            fprintf(stderr, "Error creating null thread.\n");
            perror("pthread_create");
            exit(1);
        }
    }

    /* Wait for end */
    while (run) { sleep(1); }
    if (disk_thread_id) pthread_cancel(disk_thread_id);
    pthread_cancel(net_thread_id);
    if (disk_thread_id) pthread_kill(disk_thread_id,SIGINT);
    pthread_kill(net_thread_id,SIGINT);
    pthread_join(net_thread_id,NULL);
    printf("Joined net thread\n"); fflush(stdout); fflush(stderr);
    if (disk_thread_id) {
        pthread_join(disk_thread_id,NULL);
        printf("Joined disk thread\n"); fflush(stdout); fflush(stderr);
    }

    vegas_thread_args_destroy(&null_args);

    exit(0);
}
コード例 #4
0
ファイル: vegas_hpc_lbw.c プロジェクト: andriu5/vegas_devel
int main(int argc, char *argv[]) {

    /* thread args */
    struct vegas_thread_args net_args, pfb_args, accum_args, disk_args;
    vegas_thread_args_init(&net_args);
    vegas_thread_args_init(&pfb_args);
    vegas_thread_args_init(&accum_args);
    vegas_thread_args_init(&disk_args);

    net_args.output_buffer = 1;
    pfb_args.input_buffer = net_args.output_buffer;
    pfb_args.output_buffer = 2;
    accum_args.input_buffer = pfb_args.output_buffer;
    accum_args.output_buffer = 3;
    disk_args.input_buffer = accum_args.output_buffer;

    /* Init status shared mem */
    struct vegas_status stat;
    int rv = vegas_status_attach(&stat);
    if (rv!=VEGAS_OK) {
        fprintf(stderr, "Error connecting to vegas_status\n");
        exit(1);
    }

    hputs(stat.buf, "BW_MODE", "low");
    hputs(stat.buf, "SWVER", SWVER);

    /* Init first shared data buffer */
    struct vegas_databuf *gpu_input_dbuf=NULL;
    gpu_input_dbuf = vegas_databuf_attach(pfb_args.input_buffer);

    /* If attach fails, first try to create the databuf */
    if (gpu_input_dbuf==NULL) 
        gpu_input_dbuf = vegas_databuf_create(24, 32*1024*1024,
                            pfb_args.input_buffer, GPU_INPUT_BUF);

    /* If that also fails, exit */
    if (gpu_input_dbuf==NULL) {
        fprintf(stderr, "Error connecting to gpu_input_dbuf\n");
        exit(1);
    }

    vegas_databuf_clear(gpu_input_dbuf);

    /* Init second shared data buffer */
    struct vegas_databuf *cpu_input_dbuf=NULL;
    cpu_input_dbuf = vegas_databuf_attach(accum_args.input_buffer);

    /* If attach fails, first try to create the databuf */
    if (cpu_input_dbuf==NULL) 
        cpu_input_dbuf = vegas_databuf_create(24, 32*1024*1024,
                            accum_args.input_buffer, CPU_INPUT_BUF);

    /* If that also fails, exit */
    if (cpu_input_dbuf==NULL) {
        fprintf(stderr, "Error connecting to cpu_input_dbuf\n");
        exit(1);
    }

    vegas_databuf_clear(cpu_input_dbuf);

    /* Init third shared data buffer */
    struct vegas_databuf *disk_input_dbuf=NULL;
    disk_input_dbuf = vegas_databuf_attach(disk_args.input_buffer);

    /* If attach fails, first try to create the databuf */
    if (disk_input_dbuf==NULL) 
        disk_input_dbuf = vegas_databuf_create(16, 16*1024*1024,
                            disk_args.input_buffer, DISK_INPUT_BUF);

    /* If that also fails, exit */
    if (disk_input_dbuf==NULL) {
        fprintf(stderr, "Error connecting to disk_input_dbuf\n");
        exit(1);
    }

    /* Resize the blocks in the disk input buffer, based on the exposure parameter */
    struct vegas_params vegas_p;
    struct sdfits sf;
    vegas_read_obs_params(stat.buf, &vegas_p, &sf);
    vegas_read_subint_params(stat.buf, &vegas_p, &sf);

    long long int num_exp_per_blk = (int)(ceil(DISK_WRITE_INTERVAL / sf.data_columns.exposure));
    long long int disk_block_size = num_exp_per_blk * (sf.hdr.nchan * sf.hdr.nsubband * 4 * 4);
    disk_block_size = disk_block_size > (long long int)(32*1024*1024) ? (long long int)(32*1024*1024) : disk_block_size;

    vegas_conf_databuf_size(disk_input_dbuf, disk_block_size);
    vegas_databuf_clear(disk_input_dbuf);

    signal(SIGINT, cc);

    /* Launch net thread */
    pthread_t net_thread_id;
#ifdef FAKE_NET
    rv = pthread_create(&net_thread_id, NULL, vegas_fake_net_thread,
            (void *)&net_args);
#else
    rv = pthread_create(&net_thread_id, NULL, vegas_net_thread,
            (void *)&net_args);
#endif
    if (rv) { 
        fprintf(stderr, "Error creating net thread.\n");
        perror("pthread_create");
        exit(1);
    }

    /* Launch PFB thread */
    pthread_t pfb_thread_id;

    rv = pthread_create(&pfb_thread_id, NULL, vegas_pfb_thread, (void *)&pfb_args);

    if (rv) { 
        fprintf(stderr, "Error creating PFB thread.\n");
        perror("pthread_create");
        exit(1);
    }

    /* Launch accumulator thread */
    pthread_t accum_thread_id;

    rv = pthread_create(&accum_thread_id, NULL, vegas_accum_thread, (void *)&accum_args);

    if (rv) { 
        fprintf(stderr, "Error creating accumulator thread.\n");
        perror("pthread_create");
        exit(1);
    }

    /* Launch RAW_DISK thread, SDFITS disk thread, or PSRFITS disk thread */
    pthread_t disk_thread_id;
#ifdef RAW_DISK
    rv = pthread_create(&disk_thread_id, NULL, vegas_rawdisk_thread, 
        (void *)&disk_args);
#elif defined NULL_DISK
    rv = pthread_create(&disk_thread_id, NULL, vegas_null_thread, 
        (void *)&disk_args);
#elif defined EXT_DISK
    rv = 0;
#elif FITS_TYPE == PSRFITS
    rv = pthread_create(&disk_thread_id, NULL, vegas_psrfits_thread, 
        (void *)&disk_args);
#elif FITS_TYPE == SDFITS
    rv = pthread_create(&disk_thread_id, NULL, vegas_sdfits_thread, 
        (void *)&disk_args);
#endif
    if (rv) { 
        fprintf(stderr, "Error creating disk thread.\n");
        perror("pthread_create");
        exit(1);
    }

    /* Wait for end */
    run=1;
    while (run) { 
        sleep(1); 
        if (disk_args.finished) run=0;
    }
 
#ifndef EXT_DISK
    pthread_cancel(disk_thread_id);
#endif
    pthread_cancel(pfb_thread_id);
    pthread_cancel(accum_thread_id);
    pthread_cancel(net_thread_id);
#ifndef EXT_DISK
    pthread_kill(disk_thread_id,SIGINT);
#endif
    pthread_kill(accum_thread_id,SIGINT);
    pthread_kill(pfb_thread_id,SIGINT);
    pthread_kill(net_thread_id,SIGINT);
    pthread_join(net_thread_id,NULL);
    printf("Joined net thread\n"); fflush(stdout);
    pthread_join(pfb_thread_id,NULL);
    printf("Joined PFB thread\n"); fflush(stdout);
    pthread_join(accum_thread_id,NULL);
    printf("Joined accumulator thread\n"); fflush(stdout);
#ifndef EXT_DISK
    pthread_join(disk_thread_id,NULL);
    printf("Joined disk thread\n"); fflush(stdout);
#endif
    vegas_thread_args_destroy(&net_args);
    vegas_thread_args_destroy(&pfb_args);
    vegas_thread_args_destroy(&accum_args);
    vegas_thread_args_destroy(&disk_args);

    exit(0);
}