I have a C code like this:
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int sumofinpoint=0;
int numofpoint=0;
void *montecarlo(int number)
{
srand((unsigned int)time(NULL));
float a = 2.0;
int i=0;
for (i=0;i<(int)number;i++){
float x,y;
x=((float)rand()/(float)(RAND_MAX)) * a -1;
y=((float)rand()/(float)(RAND_MAX)) * a -1;
numofpoint++;
if((x*x + y*y) <= 1){
sumofinpoint=sumofinpoint+1;
}
}
}
int main(){
pthread_t tid[15];
float pi;
int number = 100000000;
int i=0;
for(i = 0; i<15;i++){
pthread_create(&tid[i], NULL, montecarlo, (int)(number/15));
pthread_join(tid[i],NULL);
}
pi = 4*(float)sumofinpoint/(float)number;
printf("So pi la: %f",pi);
return 0;
}
I compiled it in Linux, but it said that I have "Undefined reference to pthread_create" and "Undefined reference to pthread_join". But when I compile on DevC++ in Window it runs perfectly fine. Where am I wrong?