⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 call_glss_bak.cc

📁 c++编写的并行拉马克遗传算法的程序。实现分析对接程序
💻 CC
📖 第 1 页 / 共 2 页
字号:
/* The base types */old_types_mol[0] = MPI_FLOAT;old_types_mol[1] = MPI_FLOAT;old_types_mol[2] = MPI_CHAR;old_types_mol[3] = MPI_INT;old_types_mol[4] = MPI_FLOAT;old_types_mol[5] = MPI_INT;old_types_mol[6] = mystruct_Sta;MPI_Address( &thisPop[0].mol->crdpdb, &indices_mol[0] );MPI_Address( &thisPop[0].mol->crd, &indices_mol[1] );MPI_Address( &thisPop[0].mol->atomstr, &indices_mol[2] );MPI_Address( &thisPop[0].mol->natom, &indices_mol[3] );MPI_Address( &thisPop[0].mol->vt, &indices_mol[4] );MPI_Address( &thisPop[0].mol->tlist, &indices_mol[5] );MPI_Address( &thisPop[0].mol->S, &indices_mol[6] );base_mol=indices_mol[0];for(i=0;i<7;i++)indices_mol[i] = indices_mol[i] - base_mol;MPI_Type_struct( 7, blocklens_mol, indices_mol, old_types_mol, &mystruct_mol );MPI_Type_commit( &mystruct_mol );blocklens_phe[0] = 1;blocklens_phe[1] = 1;blocklens_phe[2] = 1;blocklens_phe[3] = 1;blocklens_phe[4] = 1;blocklens_phe[5] = 1;blocklens_phe[6] = 1;/* The base types */old_types_phe[0] = MPI_UNSIGNED;old_types_phe[1] = MPI_UNSIGNED;old_types_phe[2] = MPI_DOUBLE;old_types_phe[3] = MPI_INT;old_types_phe[4] = MPI_INT;old_types_phe[5] = MPI_UNSIGNED;old_types_phe[6] = MPI_UNSIGNED;MPI_Address( &thisPop[0].phenotyp.number_of_dimensions, &indices_phe[0] );MPI_Address( &thisPop[0].phenotyp.number_of_points, &indices_phe[1] );MPI_Address( &thisPop[0].phenotyp.value, &indices_phe[2] );MPI_Address( &thisPop[0].phenotyp.lookup, &indices_phe[3] );MPI_Address( &thisPop[0].phenotyp.value_vector, &indices_phe[4] );MPI_Address( &thisPop[0].phenotyp.evalflag, &indices_phe[5] );MPI_Address( &thisPop[0].phenotyp.modified, &indices_phe[6] );base_phe=indices_phe[0];for(i=0;i<7;i++)indices_phe[i] = indices_phe[i] - base_phe;MPI_Type_struct( 7, blocklens_phe, indices_phe, old_types_phe, &mystruct_phe );MPI_Type_commit( &mystruct_phe );blocklens_Gen[0] = 1;blocklens_Gen[1] = 1;blocklens_Gen[2] = 1;blocklens_Gen[3] = 1;blocklens_Gen[4] = 1;/* The base types */old_types_Gen[0] = MPI_UNSIGNED;old_types_Gen[1] = MPI_UNSIGNED;old_types_Gen[2] = MPI_INT;old_types_Gen[3] = MPI_INT;old_types_Gen[4] = MPI_UNSIGNED;MPI_Address( &thisPop[0].genotyp.number_of_genes, &indices_Gen[0] );MPI_Address( &thisPop[0].genotyp.number_of_vectors, &indices_Gen[1] );MPI_Address( &thisPop[0].genotyp.lookup, &indices_Gen[2] );MPI_Address( &thisPop[0].genotyp.rep_vector, &indices_Gen[3] );MPI_Address( &thisPop[0].genotyp.modified, &indices_Gen[4] );base_Gen=indices_Gen[0];for(i=0;i<5;i++)indices_Gen[i] = indices_Gen[i] - base_Gen;MPI_Type_struct( 5, blocklens_Gen, indices_Gen, old_types_Gen, &mystruct_Gen );MPI_Type_commit( &mystruct_Gen );blocklens_Ind[0] = 1;blocklens_Ind[1] = 1;blocklens_Ind[2] = 1;blocklens_Ind[3] = 1;/* The base types */old_types_Ind[0] = mystruct_Gen;old_types_Ind[1] = mystruct_phe;old_types_Ind[2] = mystruct_mol;old_types_Ind[3] = MPI_UNSIGNED_LONG;MPI_Address( &thisPop[0].genotyp, &indices_Ind[0] );MPI_Address( &thisPop[0].phenotyp, &indices_Ind[1] );MPI_Address( &thisPop[0].mol, &indices_Ind[2] );MPI_Address( &thisPop[0].age, &indices_Ind[3] );base_Ind=indices_Ind[0];for(i=0;i<4;i++)indices_Ind[i] = indices_Ind[i] - base_Ind;MPI_Type_struct( 4, blocklens_Ind, indices_Ind, old_types_Ind, &mystruct_Ind );MPI_Type_commit( &mystruct_Ind );  blocklens_Pop[0] = pop_size; blocklens_Pop[1] = 1; blocklens_Pop[2] = 1;/* The base types */old_types_Pop[0] = mystruct_Ind;old_types_Pop[1] = MPI_INT;old_types_Pop[2] = MPI_INT;MPI_Address( &thisPop.heap, &indices_Pop[0] );MPI_Address( &thisPop.lhb, &indices_Pop[1] );MPI_Address( &thisPop.size, &indices_Pop[1] );indices_Pop[2] = indices_Pop[2] - indices_Pop[0];indices_Pop[1] = indices_Pop[1] - indices_Pop[0];indices_Pop[0] = 0;MPI_Type_struct( 3, blocklens_Pop, indices_Pop, old_types_Pop, &mystruct_Pop );MPI_Type_commit( &mystruct_Pop );    if (outlev > 2) { thisPop.printPopulationAsStates(logFile, pop_size, now.ntor); }    (void)fprintf( logFile, "Beginning Lamarckian Genetic Algorithm (LGA), with a maximum of %u\nenergy evaluations.\n\n", num_evals);     fprintf(stderr,"cs1_call:%d,%d,%d",myid,step,buffer_size);float cs_d[17]={1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0};thisPop[0].phenotyp=genPh_cs(thisPop[1].phenotyp,cs_d);thisPop[0].inverse_mapping();fprintf(stderr,"cs_double:%f,%f,%f\n",thisPop[0].phenotyp.value_vector[3]->gene(0),thisPop[0].phenotyp.value_vector[3]->gene(1),thisPop[0].phenotyp.value_vector[3]->gene(2));fprintf(stderr,"cs_double_2:%f,%f,%f\n",thisPop[0].genotyp.rep_vector[3]->gene(0),thisPop[0].genotyp.rep_vector[3]->gene(1),thisPop[0].genotyp.rep_vector[3]->gene(2)); Individual cs_Q;if(myid==0)cs_Q=thisPop[0];//cs_Q=thisPop[0];  Phenotype cs_Q_P;Genotype cs_Q_G;  if(myid==0)cs_Q_P=thisPop[0].phenotyp;if(myid==0)cs_Q_G=thisPop[0].genotyp;//Molecule cs_M;//if(myid==0){  //    cs_M = *(thisPop[0].mol);   //}//fprintf(stderr,"cs1_call:%d,%d,%d",myid,thisPop[0].phenotyp.number_of_points,thisPop[0].genotyp.number_of_genes);Lookup cs_L_P[thisPop[0].phenotyp.number_of_points],cs_L_G[thisPop[0].genotyp.number_of_genes];if(myid==0){for (i=0; i<thisPop[0].phenotyp.number_of_points; i++) {      cs_L_P[i] = thisPop[0].phenotyp.lookup[i];   }for (i=0; i<thisPop[0].genotyp.number_of_genes; i++) {      cs_L_G[i] = thisPop[0].genotyp.lookup[i];   }}IntVector cs_R1_P,cs_R2_P,cs_R3_P,cs_R4_P,cs_R5_P,cs_R1_G,cs_R2_G,cs_R3_G,cs_R4_G,cs_R5_G;Representation *cs_R_P[5],*cs_R_G[5];if(myid==0){cs_R1_P=thisPop[0].phenotyp.value_vector[0][0];cs_R2_P=thisPop[0].phenotyp.value_vector[1][0];cs_R3_P=thisPop[0].phenotyp.value_vector[2][0];cs_R4_P=thisPop[0].phenotyp.value_vector[3][0];cs_R5_P=thisPop[0].phenotyp.value_vector[4][0];cs_R1_G=thisPop[0].genotyp.rep_vector[0][0];cs_R2_G=thisPop[0].genotyp.rep_vector[1][0];cs_R3_G=thisPop[0].genotyp.rep_vector[2][0];cs_R4_G=thisPop[0].genotyp.rep_vector[3][0];cs_R5_G=thisPop[0].genotyp.rep_vector[4][0];}    do {        cs_flag++;                if(myid==0){        if (outlev > 1) { (void)fprintf( logFile, "Global-local search iteration %d,  Starting global search.\n", ++num_loops); }        fprintf(stderr,"global_start");        global_method->search(thisPop);        fprintf(stderr,"global_end");        if (outlev > 1) { (void)fprintf( logFile, "\tEnding global search.\n"); }        }        fprintf(stderr,"cs1_call:%d,outlev:%d,!!!_flag:%d\n",myid,outlev,cs_flag);        if (outlev > 2) { thisPop.printPopulationAsStates(logFile, pop_size, now.ntor); }        if (outlev > 3) { minmeanmax( logFile, thisPop, ++num_iterations ); }             if (outlev > 1) { (void)fprintf( logFile, "\tStarting local search.\n"); }             fprintf(stderr,"cs1_call:%d,cs_flag:%d\n",myid,cs_flag);        MPI_Barrier(MPI_COMM_WORLD);        //if(myid==0)MPI_Bcast(&thisPop,1,mystruct_Pop,0,MPI_COMM_WORLD);                MPI_Bcast(&cs_Q_G,1,mystruct_Gen,0,MPI_COMM_WORLD);        fprintf(stderr,"cs1_call:%d,cs_flag:%d*****\n",myid,cs_flag);        MPI_Bcast(cs_L_G,thisPop[0].genotyp.number_of_genes,mystruct_Lok,0,MPI_COMM_WORLD);        MPI_Bcast(&cs_Q_P,1,mystruct_phe,0,MPI_COMM_WORLD);        MPI_Bcast(cs_L_P,thisPop[0].phenotyp.number_of_points,mystruct_Lok,0,MPI_COMM_WORLD);        //MPI_Bcast(&cs_M,1,mystruct_mol,0,MPI_COMM_WORLD);        MPI_Bcast(&cs_R1_P,1,mystruct_Rep,0,MPI_COMM_WORLD);        MPI_Bcast(&cs_R2_P,1,mystruct_Rep,0,MPI_COMM_WORLD);        MPI_Bcast(&cs_R3_P,1,mystruct_Rep,0,MPI_COMM_WORLD);        MPI_Bcast(&cs_R4_P,1,mystruct_Rep,0,MPI_COMM_WORLD);        MPI_Bcast(&cs_R5_P,1,mystruct_Rep,0,MPI_COMM_WORLD);        MPI_Bcast(&cs_R1_G,1,mystruct_Rep,0,MPI_COMM_WORLD);        MPI_Bcast(&cs_R2_G,1,mystruct_Rep,0,MPI_COMM_WORLD);        MPI_Bcast(&cs_R3_G,1,mystruct_Rep,0,MPI_COMM_WORLD);        MPI_Bcast(&cs_R4_G,1,mystruct_Rep,0,MPI_COMM_WORLD);        MPI_Bcast(&cs_R5_G,1,mystruct_Rep,0,MPI_COMM_WORLD);        //MPI_Bcast(&cs_Q,1,mystruct_Ind,0,MPI_COMM_WORLD);                //cal_method->search(thisPop[1]);        cs_Q.mol=thisPop[0].mol;        cs_Q_P.lookup=cs_L_P;        cs_Q_G.lookup=cs_L_G;        cs_Q.genotyp.lookup=cs_L_P;        cs_Q.phenotyp.lookup=cs_L_G;        cs_R_P[0]=&cs_R1_P;        cs_R_P[1]=&cs_R2_P;        cs_R_P[2]=&cs_R3_P;        cs_R_P[3]=&cs_R4_P;        cs_R_P[4]=&cs_R5_P;        cs_Q_P.value_vector=cs_R_P;        cs_Q.phenotyp.value_vector=cs_R_P;        cs_R_G[0]=&cs_R1_G;        cs_R_G[1]=&cs_R2_G;        cs_R_G[2]=&cs_R3_G;        cs_R_G[3]=&cs_R4_G;        cs_R_G[4]=&cs_R5_G;        cs_Q_G.rep_vector=cs_R_G;        cs_Q.genotyp.rep_vector=cs_R_G;        fprintf(stderr,"cs_Q.x:%d,%lf,%d,%d\n",myid,cs_Q.phenotyp.value,cs_Q.phenotyp.lookup[0].vector,cs_Q.phenotyp.value_vector[3][0].mytype);        //thisPop.printPopulationAsStates(logFile, pop_size, now.ntor);                Individual cs_QQ;        cs_QQ=thisPop[0];        for(i=1;i<thisPop[0].phenotyp.number_of_points;i++)        cs_QQ.phenotyp.lookup[i]=cs_Q_P.lookup[i];        local_method->search(cs_QQ);        /*for (i=0; i<step; i++) {          fprintf(stderr,"cs_age_1:%d,%d,%d,%d\n",myid,myid*step+i,heap[i].age,thisPop[myid*step+i].age);          local_method->search(thisPop[myid*step+i]);          heap[i]=thisPop[myid*step+i];          fprintf(stderr,"cs_age:%d,%d,%d,%d\n",myid,myid*step+i,heap[i].age,thisPop[myid*step+i].age);         }*/        fprintf(stderr,"cs1_gather:%d,%d\n",myid,myid*step);        MPI_Barrier(MPI_COMM_WORLD);        MPI_Gather(heap,step,mystruct_Ind,heapall,step,mystruct_Ind,0,MPI_COMM_WORLD);              if(myid==0){         //for(i=0;i<pop_size;i++)         // {fprintf(stderr,"cs_age_2:%d,%d,%d\n",myid,heapall[i].age,i);          // }         Population thatPop(pop_size,heapall);          fprintf(stderr,"cs1_dingyi1:%d,%d,%d\n",myid,thatPop.num_individuals(),thisPop.num_individuals());         thisPop=(thatPop);                 fprintf(stderr,"cs1_dingyi2:%d\n",myid);          }                fprintf(stderr,"cs2_call:%d,%d,%d",myid,step,buffer_size);        if (outlev > 1) { (void)fprintf( logFile, "\tEnding local search.\n"); }                if (outlev > 2) { thisPop.printPopulationAsStates(logFile, pop_size, now.ntor); }        fprintf(stderr,"cs1_ca_ll:%d###outlev:%d,pop:%d",myid,outlev,sizeof(Population));    } while ((evaluate.evals() < num_evals) && (!global_method->terminate()));    MPI_Type_free(&mystruct_Pop);MPI_Type_free(&mystruct_Ind);MPI_Type_free(&mystruct_Gen);MPI_Type_free(&mystruct_phe);MPI_Type_free(&mystruct_mol);MPI_Type_free(&mystruct_Lok);MPI_Type_free(&mystruct_Rep);MPI_Type_free(&mystruct_Sta);MPI_Type_free(&mystruct_Coo);MPI_Type_free(&mystruct_Qua);        thisPop.msort(3);    return( thisPop[0].state(now.ntor) );}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -