示例#1
0
void CShellUpdater::Flush()
{
    if(m_pathsForUpdating.GetCount() > 0)
    {
        ATLTRACE("Flushing shell update list\n");

        UpdateShell();
        m_pathsForUpdating.Clear();
    }
}
示例#2
0
void CShellUpdater::Flush()
{
    if (m_pathsForUpdating.IsEmpty())
        return;

    CTraceToOutputDebugString::Instance()(__FUNCTION__ ": Flushing shell update list\n");

    UpdateShell();
    m_pathsForUpdating.Clear();
}
示例#3
0
/*****************************************************************************
 Copy a polymer structure from a replica to another 
 
 *****************************************************************************/
int ExchangePol(struct s_polymer *polymer, struct s_polymer *replica, struct s_polymer *oldp, struct s_mc_parms *parms, struct s_potential *u, int iproc, int ntemp, int even, int *ex_count, int *ex_acc, MPI_Datatype Backtype, MPI_Datatype Sidetype, MPI_Datatype Rottype, MPI_Status astatus,unsigned long long istep)
{
	int i,j,k,l, position,a=0;
	int x[ntemp];
	double delta,denomT;
	double E[ntemp];
	int nback = polymer->nback;
	int buffer_back_size=sizeof(struct s_back)*nback;
	int nosidechains=parms->nosidechains;
	int ipolymer;


	E[iproc]=polymer->etot;


	if(iproc==0) CountContacts(stderr,polymer,parms,istep);


	MPI_Barrier(MPI_COMM_WORLD);
	for(i=0;i<ntemp;i++)
		MPI_Bcast(&(E[i]),1,MPI_DOUBLE,i,MPI_COMM_WORLD);  //exchanging energy values between replicas
	MPI_Barrier(MPI_COMM_WORLD);
	//DEBUG
/*	if(iproc==0)
	for(i=0;i<ntemp;i++)
	{
//			fprintf(stderr,"step %llu E[%d]=\t%lf\n",istep,i,E[i]);
	}
*/	for(i=even;i<ntemp-1;i=i+2)
	{
		if(iproc==i) //sender		
		{		
			delta = -(E[i]-E[i+1]);
			denomT = (parms->T[i]*parms->T[i+1])/(parms->T[i+1]-parms->T[i]) ;
			if(Metropolis(delta,denomT,polymer->tables)==1) a=1; 	

			MPI_Send(&a, 1, MPI_INT, i+1, 1000000+i, MPI_COMM_WORLD); 
			
			#ifdef DEBUG
                        if(parms->debug>2) fprintf(stderr,"i=%d\tT(i)=%f\tT(i+1)=%f\tdelta=%f\tacc=%d\n",i,parms->T[i],parms->T[i+1],delta,a);
			#endif			
		}
		if(iproc==i+1) MPI_Recv(&a, 1, MPI_INT, i, 1000000+i, MPI_COMM_WORLD, &astatus); //receiver
		MPI_Barrier(MPI_COMM_WORLD); 
		if(a==1) //confirmed exchange
		{	
			if(iproc==i) fprintf(stderr,"[EX]\t%llu\t%d\t%d\n",istep,i,i+1); 	

		for(ipolymer=0;ipolymer<parms->npol;ipolymer++)
		{
				
			nback=(polymer+ipolymer)->nback;
			buffer_back_size=sizeof(struct s_back)*nback;
			char *buffer_back=malloc(buffer_back_size);

			if(iproc==i)
			{
				position=0;
				for(j=0;j<nback;j++)
        		                MPI_Pack(((polymer+ipolymer)->back)+j,1,Backtype,buffer_back,buffer_back_size,&position,MPI_COMM_WORLD);
	                         MPI_Send(buffer_back,position,MPI_PACKED,i+1, 10000+100*i, MPI_COMM_WORLD);
			}
			if(iproc==i+1)
			{
				MPI_Recv(buffer_back,buffer_back_size,MPI_PACKED,i,10000+100*i, MPI_COMM_WORLD, &astatus);
		                position=0;
                		for(j=0;j<nback;j++)
	               	        	MPI_Unpack(buffer_back,buffer_back_size,&position,((replica+ipolymer)->back)+j,1,Backtype,MPI_COMM_WORLD);

				position=0;
			
				for(j=0;j<nback;j++)
                                        MPI_Pack(((polymer+ipolymer)->back)+j,1,Backtype,buffer_back,buffer_back_size,&position,MPI_COMM_WORLD);
	                        MPI_Send(buffer_back,position,MPI_PACKED,i, 20000+100*i, MPI_COMM_WORLD);

			}
			
			if(iproc==i)
			{
			        MPI_Recv(buffer_back,buffer_back_size,MPI_PACKED,i+1, 20000+100*i, MPI_COMM_WORLD, &astatus);
                                position=0;
                                for(j=0;j<nback;j++)
                                        MPI_Unpack(buffer_back,buffer_back_size,&position,((replica+ipolymer)->back)+j,1,Backtype,MPI_COMM_WORLD);


			}
			
			if(!nosidechains)
			{

				int side_dims[nback];
				int rot_dims[nback];
               			int buffer_side_size,sidechains=0;
				int rotamersl=0;
			        for(j=0;j<nback;j++)
                		{
                        		side_dims[j]=(((polymer+ipolymer)->back)+j)->nside;
					rot_dims[j]=(((polymer+ipolymer)->back)+j)->nrot;
					sidechains+=side_dims[j];
					rotamersl+=rot_dims[j];
                		}

		                buffer_side_size=sizeof(struct s_side)*sidechains;
    				char *buffer_side=malloc(buffer_side_size);
				if(iproc==i)
				{
					position=0;
					for(j=0; j<nback;j++) for(k=0; k<side_dims[j];k++)
						MPI_Pack(((((polymer+ipolymer)->back)+j)->side)+k,1,Sidetype,buffer_side,buffer_side_size,&position,MPI_COMM_WORLD);	
					MPI_Send(buffer_side,position,MPI_PACKED,i+1, 1000000+100*i, MPI_COMM_WORLD);
				}
				if(iproc==i+1) 
				{
					MPI_Recv(buffer_side,buffer_side_size,MPI_PACKED,i,1000000+100*i, MPI_COMM_WORLD, &astatus);
					position=0;
					for(j=0; j<nback;j++) for(k=0; k<side_dims[j];k++) 
						MPI_Unpack(buffer_side,buffer_side_size,&position,((((replica+ipolymer)->back)+j)->side)+k,1,Sidetype,MPI_COMM_WORLD);
				}


				//rotamers	i -> i+1
				if(iproc==i)
				{
//					position=0;
					for(j=0; j<nback;j++) for(k=0; k<side_dims[j];k++) for(l=0; l<rot_dims[j]; l++)
//								MPI_Pack((((((polymer->back)+j)->side)+k)->rot)+l,1,Rottype,buffer_rot,buffer_rot_size,&position,MPI_COMM_WORLD);
//					MPI_Send(buffer_rot,position,MPI_PACKED,i+1, 2000000+1000*i, MPI_COMM_WORLD);
						MPI_Send(((((((polymer+ipolymer)->back)+j)->side)+k)->rot)+l, 1, Rottype, i+1, 2000000+1000*i+100*j+10*k+l, MPI_COMM_WORLD);
				}

				if(iproc==i+1)
				{
//					MPI_Recv(buffer_rot,buffer_rot_size,MPI_PACKED,i,2000000+1000*i, MPI_COMM_WORLD, &astatus);
//					position=0;
					for(j=0; j<nback;j++) for(k=0; k<side_dims[j];k++) for(l=0; l<rot_dims[j]; l++)
//						MPI_Unpack(buffer_rot,buffer_rot_size,&position,(((((replica->back)+j)->side)+k)->rot)+l,1,Rottype,MPI_COMM_WORLD);
						MPI_Recv(((((((replica+ipolymer)->back)+j)->side)+k)->rot)+l, 1, Rottype, i, 2000000+1000*i+100*j+10*k+l , MPI_COMM_WORLD, &astatus);	
				}

			
		//}
				//sidechains	i+i -> i
	//	if(!nosidechains)
	//	{	
				if(iproc==i+1)
				{
					position=0;
                                        for(j=0; j<nback;j++) for(k=0; k<side_dims[j];k++)
                                               MPI_Pack(((((polymer+ipolymer)->back)+j)->side)+k,1,Sidetype,buffer_side,buffer_side_size,&position,MPI_COMM_WORLD);
                                        MPI_Send(buffer_side,position,MPI_PACKED,i, 3000000+100*i, MPI_COMM_WORLD);

//					 for(j=0; j<nback;j++) for(k=0; k<((polymer->back)+j)->nside;k++) 
//						MPI_Send((((polymer->back)+j)->side)+k, 1, Sidetype, i, 3000000+100*i+10*j+k, MPI_COMM_WORLD);
				}
				if(iproc==i)
				{
	  		              	MPI_Recv(buffer_side,buffer_side_size,MPI_PACKED,i+1,3000000+100*i, MPI_COMM_WORLD, &astatus);
                                      	position=0;
                                        for(j=0; j<nback;j++) for(k=0; k<side_dims[j];k++)
                                                MPI_Unpack(buffer_side,buffer_side_size,&position,((((replica+ipolymer)->back)+j)->side)+k,1,Sidetype,MPI_COMM_WORLD);
//					for(j=0; j<nback;j++) for(k=0; k<((replica->back)+j)->nside;k++)
//						MPI_Recv((((replica->back)+j)->side)+k, 1, Sidetype, i+1, 3000000+100*i+10*j+k, MPI_COMM_WORLD, &astatus);
				}

				//rotamers 	i+1 -> i
				if(iproc==i+1)
				{
/*					position=0;
 	                                for(j=0; j<nback;j++) for(k=0; k<((polymer->back)+j)->nside;k++) for(l=0; l<rot_dims[j]; l++)
                                                MPI_Pack((((((polymer->back)+j)->side)+k)->rot)+l,1,Rottype,buffer_rot,buffer_rot_size,&position,MPI_COMM_WORLD);
                                       MPI_Send(buffer_rot,position,MPI_PACKED,i, 4000000+1000*i, MPI_COMM_WORLD);
*/
					 for(j=0; j<nback;j++) for(k=0; k<(((polymer+ipolymer)->back)+j)->nside;k++) for(l=0; l<(((polymer+ipolymer)->back)+j)->nrot; l++)
						MPI_Send(((((((polymer+ipolymer)->back)+j)->side)+k)->rot)+l, 1, Rottype, i, 4000000+1000*i+100*j+10*k+l, MPI_COMM_WORLD);
				}
		
				if(iproc==i)
				{
/*					MPI_Recv(buffer_rot,buffer_rot_size,MPI_PACKED,i+1,4000000+1000*i, MPI_COMM_WORLD, &astatus);
                                        position=0;
                                       for(j=0; j<nback;j++) for(k=0; k<((replica->back)+j)->nside;k++) for(l=0; l<rot_dims[j]; l++)
                                        MPI_Unpack(buffer_rot,buffer_rot_size,&position,(((((replica->back)+j)->side)+k)->rot)+l,1,Rottype,MPI_COMM_WORLD);
*/
					 for(j=0; j<nback;j++) for(k=0; k<(((replica+ipolymer)->back)+j)->nside;k++) for(l=0; l<(((replica+ipolymer)->back)+j)->nrot; l++)
						MPI_Recv(((((((replica+ipolymer)->back)+j)->side)+k)->rot)+l, 1, Rottype, i+1, 4000000+1000*i+100*j+10*k+l , MPI_COMM_WORLD, &astatus);	
				}
		
				free(buffer_side);
			}
			free(buffer_back);		
		}//end of ipolymer loop	

		ex_acc[i]++;	//accepted exchange counter
			x[i]=1; x[i+1]=1;		


		

		}//end of accepted exchange
		// if not accepted 
		else
		{
		x[i]=0; x[i+1]=0;
		}	
		ex_count[i]++; //tried exchange counter
		a=0;
	}
	
	if(x[iproc]==1)
	{
		CopyAllPolymers(replica,polymer,parms->npol,parms->nosidechains,parms->nosidechains);
		CopyAllPolymers(replica,oldp,parms->npol,parms->nosidechains,parms->nosidechains);

		//etot=Totalenergy : polymer and oldp contacts must be recomputed
		polymer->etot = TotalEnergy(polymer,u,parms,parms->npol,1,parms->nosidechains,parms->debug,iproc);
		oldp->etot=TotalEnergy(oldp,u,parms,parms->npol,1,parms->nosidechains,parms->debug,iproc);

		if (parms->shell==1)
		{
			UpdateShell(polymer,parms);
			CopyShell(polymer,oldp,parms);	
			parms->ishell=0;
		}
	}	

//	free(buffer_back);

	return a;
}