Пример #1
0
int main(int argc, char * argv[])
{
    size_t bytes = (argc>1) ? atol(argv[1]) : 1024*1024;

    int avail = hbw_check_available();
    printf("%s returned %s\n", "hbw_check_available", avail==0 ? "SUCCESS" : "FAILURE");
    assert(avail == 0);

    void * a = hbw_malloc(bytes);
    assert(a != NULL);
    hbw_free(a);

    void * b = hbw_calloc(bytes, 1);
    assert(b != NULL);
    hbw_free(b);

    void * c = hbw_realloc(NULL, bytes);
    printf("hbw_realloc c=%p\n", c);
    assert(c != NULL);

    void * d = hbw_realloc(c, 0);
    printf("hbw_realloc c=%p d=%p\n", c, d);

    void * e = NULL;
    int rc = hbw_posix_memalign(&e, 4096, bytes);
    printf("hbw_posix_memalign rc=%d e=%p\n", rc, e);
    assert(rc == 0 && e != NULL);

    return 0;
}
Пример #2
0
int main (int argc, char *argv[])
{
    void *ptr;
    int err = 0;

    hbw_set_policy(HBW_POLICY_BIND);

    printf ("Allocating 400 KB with 1GB pages\n");
    err = hbw_posix_memalign_psize (&ptr,
                                    1073741824,
                                    409600,
                                    HBW_PAGESIZE_1GB);

    if (err) {
        fprintf(stderr, "ERROR: hbw_posix_memalign_size()\n");
    }
    if (!err) {
        memset (ptr, 0, 409600);
        printf ("Reallocing 100KB with 1GB pages\n");
        ptr = hbw_realloc (ptr, 102400);
        if (ptr == NULL) {
            fprintf(stderr, "ERROR: hbw_realloc()\n");
            err = -1;
        }
    }
    if (!err) {
        memset (ptr, 0, 102400);
        printf ("Reallocing 1GB with 1GB pages\n");
        ptr = hbw_realloc (ptr, 1073741824);
        if (ptr == NULL) {
            fprintf(stderr, "ERROR: hbw_realloc()");
            err = -1;
        }
    }
    if (!err) {
        memset (ptr, 0, 1073741824);
        printf ("Reallocing 1073742848 with 1GB pages\n");
        ptr = hbw_realloc (ptr, 1073742848);
        if (ptr == NULL) {
            fprintf(stderr, "ERROR:  hbw_realloc()\n");
            err = -1;
        }
    }
    if (!err) {
        memset (ptr, 0, 1073742848);
    }
    if (ptr) {
        hbw_free(ptr);
    }

    return err;
}
Пример #3
0
static PetscErrorCode PetscHBWRealloc(size_t a,int lineno,const char function[],const char filename[],void **result)
{
#if !defined(PETSC_HAVE_MEMKIND)
  return PetscReallocAlign(a,lineno,function,filename,result);
#else
  if (!a) {
    int ierr = PetscFreeAlign(*result,lineno,function,filename);
    if (ierr) return ierr;
    *result = NULL;
    return 0;
  }
  *result = hbw_realloc(*result,a);
  if (!*result) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_MEM,"Memory requested %.0f",(PetscLogDouble)a);
  return 0;
#endif
}