What do folks here make of this?

 ww


Hi,

Here at U of M we have an 8 processor machine with about 3G of RAM. The
following, _very_ simple program creates 90 threads, in each thread 10M
is allocated and a simple pointless write is performed on the RAM 10x.
Now, the program runs just fine on a 1 processor system, but on
multiprocessors, memory is NOT allocated sometimes (NULL returned
meaning that the kernel is not re-entrant).

The REAL problem is with the execution speed. If this program is run on
a multiprocessor system in the bg, and top is executed, the processes
only get ~15% of the CPU time, and the system gets a whopping 400% and
about 385% idle. (* processors - 800%).

If I use a fork and multiply processes, the CPU is used about 799%, 1%
system, 0 idle.

The Question is WHY???? I'm pulling my hair out here! HELP! [I have
enclosed the source]

Thanks in advance,
Adam

+++++ SOURCE: TEST1.C ++++++
#include <pthread.h>

pthread_t   Processes[90];
pthread_cond_t Wait;
pthread_mutex_t mutex;

int nProcesses;

void ThreadStart(void *)
{
  int i,j;
  char *M = (char *)malloc(10000000);

if(M!=NULL){
  for(i=0;i<10;++i)
    for(j=0;j<10000000;++j)
      M[j] = (char)i;
}
else{
 printf("Allocation FAILED!! - %d\n", nProcesses);
 goto End;
}
  printf("Complete....\n");

End:
  pthread_mutex_lock(&mutex);
  nProcesses--;
  pthread_mutex_unlock(&mutex);

  pthread_cond_signal(&Wait);
  pthread_exit(0);
}

void main()
{
  int i;

  pthread_mutex_init(&mutex, NULL);
  pthread_cond_init(&Wait, NULL);

  pthread_mutex_lock(&mutex);

  for(i=0, nProcesses=0;i<90;++i, nProcesses++)
    {
        pthread_create(&Processes[i], NULL, (void * (*)(void
*))ThreadStart, NULL);
    }

    // waits for threads to finish
  while(nProcesses>0) pthread_cond_wait(&Wait, &mutex);
}




Reply via email to