problem allocating large amount of memory

Bill Broadley bill at cse.ucdavis.edu
Wed Dec 3 22:28:33 EST 2003


On Wed, Dec 03, 2003 at 06:24:47PM -0800, Roland Krause wrote:
> What I am not able to do currently is to get the 2.95GB all at once.
> "But I must have it all."

A small example program is useful.

I'll include one that works for me.  Here's the output of the run:

[root at quad root]# gcc -Wall -Wno-long-long -pedantic memfill.c -o memfill && ./memfill
Array size of 483183820 doubles (3.60 GB) allocated
Initialized 1GB.
Initialized 1GB.
Initialized 1GB.
Initialized 1GB.
Sleeping for 60 seconds so you can check top.

  PID USER     PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM   TIME CPU COMMAND
17182 root      25   0 3584M 3.5G   340 S     0.0 48.4   0:10   3 memfill
 
I'll attach my source.  This particular machine has 8GB ram, but it
would be kinda strange for this to fall just because it's virtual.

You do have enough swap right?

-- 
Bill Broadley
Information Architect
Computational Science and Engineering
UC Davis
-------------- next part --------------
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define RAM_USED 3.6   /* 3.6 GB */
#define GB 1073741824  /* bytes per GB */

int main()
{
	double *x;
	long long i;
	long long array_size;

	array_size=RAM_USED*GB/sizeof(double);	
	x=malloc(RAM_USED*GB);
	if (x)
	{
		printf ("Array size of %lld doubles (%3.2f GB) allocated\n",array_size,RAM_USED);
		for (i=0;i<array_size;i++)
		{
			x[i]=i;
			if (i%(GB/sizeof(double))==0)
			{ 
				printf ("Initialized 1GB.\n");
			}
		}
		printf ("Sleeping for 60 seconds so you can check top.\n");
		sleep(60);
		return(0);
	}	
	printf ("We couldn't allocate an array of %3.2f GB!\n",RAM_USED);
	return(-1);
}
	
-------------- next part --------------
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define RAM_USED 3.6   /* 3.6 GB */
#define GB 1073741824  /* bytes per GB */

int main()
{
	double *x;
	long long i;
	long long array_size;

	array_size=RAM_USED*GB/sizeof(double);	
	x=malloc(RAM_USED*GB);
	if (x)
	{
		printf ("Array size of %lld doubles (%3.2f GB) allocated\n",array_size,RAM_USED);
		for (i=0;i<array_size;i++)
		{
			x[i]=i;
			if (i%(GB/sizeof(double))==0)
			{ 
				printf ("Initialized 1GB.\n");
			}
		}
		printf ("Sleeping for 60 seconds so you can check top.\n");
		sleep(60);
		return(0);
	}	
	printf ("We couldn't allocate an array of %3.2f GB!\n",RAM_USED);
	return(-1);
}
	


More information about the Beowulf mailing list