3,881
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include <string.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#define POPSIZE 5
#define NVARS 12
#define MAXGENS 2000
#define EXNUM 3
struct genotype
{
char gene[NVARS];
double fitness;
double rfitness;
double cfitness;
}*population,*newpopulation,*localbest;
int numprocs,myid;
FILE *galog;
int generation;
char cmp[NVARS];
double lowfitness;
char temp[NVARS];
void report(){
int i;
for(i=0;i<POPSIZE;i++)
printf("pid:%d\tseq:%s\tscore:%.1f\n",myid,population[i].gene,population[i].fitness);fflush(stdout);
printf("pid:%d\tcmp:%s\tlowfitness:%.1f\tbest:%s\tfit:%.1f\n",myid,cmp,lowfitness,localbest[0].gene,localbest[0].fitness);fflush(stdout);
}
int _tmain(int argc, char* argv[])
{
double starttime=0.0;
double endtime;
int i,j,flag;
int n=0;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
fprintf(stdout,"Process %d of %d start....\n",myid,numprocs);
fflush(stdout);
galog=stdout;
generation=0;
if(myid==numprocs-1){
srand(time(0));
starttime=MPI_Wtime();
}
initialize();
//evaluate();
//keepthebest();
report();
MPI_Finalize();
getchar();
return 0;
}