#include <stdio.h>
#include <stdlib.h>
int main(){
  int k,l;
  unsigned int m,p;
  const int mem=1800000000;
  const int chunk=262144;
  int len;
  double **dptr;
  int multiple;
  
  m=sizeof(double)+sizeof(double*);
  multiple=chunk/sizeof(double);
  len=mem/m/multiple;
  dptr = (double **) malloc(sizeof(double*)*len) ;
  for(k=0; k<len; k++) {
    dptr[k] = (double *) malloc(chunk) ;
    if(!dptr[k]) {
      printf("k: %d",k);
      printf("Alloc Null\n");
      exit(-1);
     }
    for (l=0;l<multiple;l++){
      *(dptr[k]+l) = rand();
    }
  }
  for(k=len-1; k>=0; k--) {
    for (l=0;l<multiple;l++){
      printf("k %d value: %d\n",k,*(dptr[k]+l));
    }
  }
  fprintf(stderr,"k=%d mem=%d MB chunk=%d\n",k,mem/1000000, chunk);
  exit (0);
}



