Making a thread program which takes segments of an array then processes them with a computation in multiple threads. Will be testing between 1-8. The array is of a big size so that it takes some time to process so that I can see changes when I add threads.
for (int i = segment->aStart; i < (segment->aStart + segment->length); i+=1)
{
// First populate array with random numbers between 1-100
segment->dataArray[i] = (1+ rand() % 100);
// Divide and multiply each element of the array by 100 random numbers upto 5
for (int j = 0; j < 2; j++)
{
segment->dataArray[i] = (segment->dataArray[i]*(2+rand() % 10));
}
}
}
int main()
{
int* dArray;
dArray = new int[ARRAYSIZE];
int segmentSize;
// Time Variables
timeval start, stop, result;
float t;
srand((unsigned)time(NULL));
cout << "Processing and Thread Testing with an Array of Random Numbers" << endl;
// Thread setup
for(int i = 1; i <= THREADS; i+=1)
{
// Thread Data Setup
pthread_t* thread = new pthread_t[THREADS];
arrayStruct* segment = new arrayStruct[THREADS];
segmentSize = ARRAYSIZE/THREADS;
void* exitStatus;
The error message is not the happiest one (you ought to post it, by the way) dArray = newint dataArray[ARRAYSIZE]; ¿why did you write `dataArray' there?
Edit: OK, you did post it. ¿But why leave out critical information like the line number?