Esempio n. 1
0
int dotest ()
{
    int v,p;
    double *d;
    time_t tbegin, tput, tget;
    alloc_vars();
    qhashtbl_t *tbl = qhashtbl(range);

    /* Put all data values with path/var into hashtable */
    printf("============== PUT DATA INTO HASHTABLE ============\n");
    time (&tbegin);
    for (p=0; p<npaths; p++) {
        for (v=0; v<nvars; v++) {
            tbl->put2(tbl, varpaths[p], varnames[v], &data[p*nvars+v]);
        }
    }
    time (&tput);
    tput = tput - tbegin;

    /* Get each element and check value */
    printf("============== GET DATA FROM HASHTABLE ============\n");
    time (&tbegin);
    for (p=npaths-1; p>=0; p--) {
        for (v=nvars-1; v>=0; v--) {
            d = tbl->get2(tbl, varpaths[p], varnames[v]);
            if (d == NULL) {
                printf ("ERROR: stored value for p=%d,v=%d not found in hash table\n",
                        p, v);
                return 1;
            } else if (*d != data[p*nvars+v]) {
                printf ("ERROR: for p=%d,v=%d, found value = %lf in hash table != "
                        "what was put in = %lf\n",
                        p, v, *d, data[p*nvars+v]);
                return 2;
            }

        }
    }
    time (&tget);
    tget = tget - tbegin;
    printf("Timing: put %d elements in %ld seconds, got them back in %ld seconds\n",
            npaths*nvars, (long)tput, (long)tget);

    /* Print hashtable */
    printf("============== PRINT HASHTABLE ============\n");
    tbl->debug(tbl,NULL,0);

    /* Free hashtable */
    tbl->free(tbl);

    free_vars();
    return 0;
}
Esempio n. 2
0
/**
 * Create a server object.
 */
ad_server_t *ad_server_new(void) {
    if (initialized) {
        initialized = true;
        //evthread_use_pthreads();
    }

    ad_server_t *server = NEW_OBJECT(ad_server_t);
    if (server == NULL) {
        return NULL;
    }

    // Initialize instance.
    server->options = qhashtbl(0, 0);
    server->stats = qhashtbl(100, QHASHTBL_THREADSAFE);
    server->hooks = qlist(0);
    if (server->options == NULL || server->stats == NULL || server->hooks == NULL) {
        ad_server_free(server);
        return NULL;
    }

    DEBUG("Created a server object.");
    return server;
}
Esempio n. 3
0
ADIOS_FILE*
adios_read_icee_open(const char * fname,
                     MPI_Comm comm,
                     enum ADIOS_LOCKMODE lock_mode,
                     float timeout_sec)
{
    log_debug("%s\n", __FUNCTION__);

    icee_llist_ptr_t head = NULL;

    float waited_sec = 0.0;    
    while (waited_sec <= timeout_sec)
    {
        head = icee_llist_search(icee_filelist, icee_fileinfo_checkname, 
                                 (const void*) fname);
        if (head != NULL)
            break;

        usleep(0.1*1E6);
        waited_sec += 0.1;
    }
    
    if (head == NULL)
    {
        log_error ("No data yet\n");
        return NULL;
    }
    
    icee_fileinfo_rec_ptr_t fp = (icee_fileinfo_rec_ptr_t)head->item;
    
    while (fp->merge_count != fp->nchunks)
    {
        log_debug("Waiting the rest of blocks (%d/%d)\n", fp->merge_count, fp->nchunks);
        
        usleep(0.1*1E6);
    }

    ADIOS_FILE *adiosfile = malloc(sizeof(ADIOS_FILE));

    adiosfile->fh = (uint64_t)fp;

#if 0
    int hashsize = 10;
    qhashtbl_t *tbl = qhashtbl(hashsize);
    
    icee_varinfo_rec_ptr_t vp = fp->varinfo;
    while (vp != NULL)
    {
        tbl->put(tbl, vp->varname, NULL);
        vp = vp->next;
    }

    adiosfile->nvars = tbl->size(tbl);
    adiosfile->var_namelist = malloc(tbl->num * sizeof(char *));

    int i;
    size_t idx = 0;
    for (i=0; i<hashsize; i++)
    {
        qhnobj_t *qhobj = tbl->slots[i].head;
        while (qhobj != NULL)
        {
            //DUMP("%lu:%s", idx, qhobj->key);
            adiosfile->var_namelist[idx] = strdup(qhobj->key);
            qhobj->value = (void*) idx;
            idx++;
            qhobj = qhobj->next;
        }
    }

    /*
    // Update back to varinfo
    vp = fp->varinfo;
    while (vp != NULL)
    {
    vp->varid = (int) tbl->get(tbl, vp->varname);
    vp = vp->next;
    }
    */

    tbl->free(tbl);
#endif

    adiosfile->nvars = fp->nvars;
    adiosfile->var_namelist = malloc(fp->nvars * sizeof(char *));

    icee_varinfo_rec_ptr_t vp = fp->varinfo;

    int i;
    for (i = 0; i < fp->nvars; i++)
    {
        adiosfile->var_namelist[i] = strdup(vp->varname);
        vp = vp->next;
    }

    adiosfile->nattrs = 0;
    adiosfile->attr_namelist = NULL;

    adiosfile->current_step = 0;
    adiosfile->last_step = 1;

    adiosfile->path = strdup(fname);

    adiosfile->version = -1;
    adiosfile->file_size = 0;
    adios_errno = err_no_error;        

    return adiosfile;
}