openMPにしたいのですが
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "dSFMT.h"
#include <sys/time.h>
#include <omp.h>
#define T_END 100
#define BIRTH_RATE 1.0
#define DEATH_RATE 0.1
#define ALLEE_EFFECT 0.5
#define T_DENSITY 10.0
#define PROPAGULE_SIZE 5
#define SD_INTERACTION 1.0
#define SD_DISPERSAL 1.0
struct timeval start_timeval,end_timeval;
int getutimer (struct timeval *start,struct timeval *end) {
return ( ((int)end->tv_sec - (int)start->tv_sec)*1000000+((int)end->tv_usec - (int)start->tv_usec) );
}
/* Properties of an individual */
typedef struct individual {
double x, y, local_density;
struct individual *next_indiv;
}INDIVIDUAL;
void calc_local_density(INDIVIDUAL *);
double birth_rate(double);
double death_rate(double);
void birth(INDIVIDUAL*);
void death(INDIVIDUAL*);
void dispersal(INDIVIDUAL*);
void display_list(INDIVIDUAL*);
void write_to_file(INDIVIDUAL*, int, double, double);
INDIVIDUAL *make_new_indiv();
INDIVIDUAL *add_next_indiv(INDIVIDUAL*);
double weight(double);
double distance(INDIVIDUAL*, INDIVIDUAL*);
double sqr(double);
int number_of_indivs(INDIVIDUAL*, double*, double*);
dsfmt_t dsfmt;
FILE *fp;
int main(){
int seed;
INDIVIDUAL *list_head, *indiv;
int i, t;
double xcenter, ycenter;
gettimeofday(&start_timeval,NULL);
seed=(long)time(NULL);
dsfmt_init_gen_rand(&dsfmt, seed);
fp = fopen("output.dat","w");
list_head = make_new_indiv();
indiv = list_head;
for(i=0; i<PROPAGULE_SIZE; i++){
indiv = add_next_indiv(indiv);
indiv->x = 0.0;
indiv->y = 0.0;
indiv->local_density = 0.0;
}
write_to_file(list_head, 0, 0.0, 0.0);
for(t = 1; t <= T_END; t++){
dispersal(list_head);
death(list_head);
calc_local_density(list_head);
birth(list_head);
printf("Time = %d, Population size =%d\n", t, number_of_indivs(list_head, &xcenter, &ycenter));
write_to_file(list_head, t, xcenter, ycenter);
}
time(&time2);
gettimeofday(&end_timeval,NULL);
printf("%d %d, %d\n", time1, time2, time2 - time1); //??
printf("マイクロ秒:%d \n",getutimer(&start_timeval, &end_timeval));
return 0;
}
・
・
・
・
int number_of_indivs(INDIVIDUAL *list_head, double *xcenter, double *ycenter){
int count = 0;
double xsum = 0.0, ysum = 0.0;
INDIVIDUAL *indiv;
for(indiv = list_head->next_indiv; indiv != NULL; indiv = indiv->next_indiv){
xsum += indiv->x;
ysum += indiv->y;
count++;
}
*xcenter = xsum/(double)count;
*ycenter = ysum/(double)count;
return count;
}
をopenMpにしたいのですがなかなか上手くいきません。
人口のシミュレーションなのですが、人が増えるたびに計算回数が増えるのでなんとかしたいのですが・・・
すべてのソースコードを記載ようとしたのですが、文字制限で載せられませんでした・・・
どうかお助けください。。
よろしくお願いいたします。