Ejemplo n.º 1
0
void snapshot(double ***f1,double **nu,double t_cur,long count)
{
char str[256];
char message[10]="message";
long tag=count,v;
FILE *fd;

 sprintf(str,"%s_%d_%ld.snp",NameSnapFile,size,count);
 boundary_conditions(f1,nut);

 if(rank!=0) MPI_Recv(message,0,MPI_CHAR,rank-1,tag,MPI_COMM_WORLD,statuses);

 fd=fileopen(str,rank);
 Master nmessage("snap has been started",t_cur,count);
 Master fprintf(fd,"current time = %0.10f \ncurrent iteration = %ld\n",t_cur,count);
 Master fprintf(fd,"number of processors along axes={%d,%d}\n",pp[0],pp[2]);
 Master fprintf(fd,"Number of points along x = %d\n",N1);
 Master fprintf(fd,"Number of points along z = %d\n",N3);
 Master fprintf(fd,"Reynolds number = %lf\n",Re);

 for(v=0;v<nvar;v++)
    print_array2d(fd,f1[v],0,m1,0,m3);
 print_array2d(fd,nu,0,m1,0,m3);
 fileclose(fd);
                  
 if(rank!=size-1) MPI_Send(message,0,MPI_CHAR,rank+1,tag,MPI_COMM_WORLD);
 MPI_Barrier(MPI_COMM_WORLD);
 Master {nmessage("snap is done",t_cur,count);
                   add_control_point(str);}
}
Ejemplo n.º 2
0
void dump(double ***f1,double **nu,double t_cur,long count)
{
char str[256],str1[256];
FILE *fd;
int v;
struct stat st = {0};

if (stat("dump", &st) == -1) {
	mkdir("dump", 0777);
}
 if(DumpKeep)  sprintf(str,"dump/%s_%d_%ld.dmp",NameSnapFile,rank,count);
	else {
		sprintf(str,"dump/%s%d.dmp",NameSnapFile,rank);
		sprintf(str1,"dump/%s%d.bak",NameSnapFile,rank);
		remove(str1);
		rename(str,str1);
		}
// if(rank!=0) MPI_Recv("dump",0,MPI_CHAR,rank-1,/*tag*/1,MPI_COMM_WORLD,statuses);

 fd=fileopen(str,rank);

//Master { // для вывода в один файл, иначе убрать!! 
// nmessage("dump has been started",t_cur,count);
 fprintf(fd,"current time = %0.10f \ncurrent iteration = %ld\n",t_cur,count);
 fprintf(fd,"number of processors along axes={%d,%d}\n",pp[0],pp[2]);
 fprintf(fd,"Number of points along x = %d\n",N1);
 fprintf(fd,"Number of points along z = %d\n",N3);
 fprintf(fd,"Reynolds number = %lf\n",Re);
//}

 for(v=0;v<nvar;v++)
    print_array2d(fd,f1[v],0,m1,0,m3);
 print_array2d(fd,nu,0,m1,0,m3);
 fileclose(fd);

// if(rank!=size-1) MPI_Send(message,0,MPI_CHAR,rank+1,tag,MPI_COMM_WORLD);
 MPI_Barrier(MPI_COMM_WORLD);
 Master 
    {   
	 nmessage("dump is done",t_cur,count);
	 if(DumpKeep)  sprintf(str,"dump/%s_*_%ld.dmp",NameSnapFile,count);
		else 	sprintf(str,"dump/%s*.dmp",NameSnapFile);
    add_control_point(str);
    }
}
Ejemplo n.º 3
0
int main( int argc, char** argv )
{
	int i = 0;
	int j = 0;
	int ar[YSZ][XSZ] = { { 0 } };
	int lut[YSZ][XSZ] = { { 0 } };
	
	srand(time(NULL));

	for( i = 0; i < YSZ; i++ )
		for( j = 0; j < XSZ; j++ )
			ar[i][j] = rand() % MAX + 1;


	print_array2d( ar, XSZ, YSZ );
	printf( "max recursive: %i\n", find_max_r( ar, XSZ, YSZ, 0, 0 ) );
	

	return 0;
}
int main(void)
{
    int tmp_edges[12], tmp_vertices[8];

    /* identity */
    transform(identity_edges, identity_vertices);

    /* rotation around X axis */
    init(tmp_edges, tmp_vertices);
    for (int i = 0; i < 3; ++i) {
        apply(tmp_edges, tmp_edges, x_edges, 12);
        apply(tmp_vertices, tmp_vertices, x_vertices, 8);
        transform(tmp_edges, tmp_vertices);
    }

    /* rotation around Y axis */
    init(tmp_edges, tmp_vertices);
    for (int i = 0; i < 3; ++i) {
        apply(tmp_edges, tmp_edges, y_edges, 12);
        apply(tmp_vertices, tmp_vertices, y_vertices, 8);
        transform(tmp_edges, tmp_vertices);
    }

    /* rotation around Z axis */
    init(tmp_edges, tmp_vertices);
    for (int i = 0; i < 3; ++i) {
        apply(tmp_edges, tmp_edges, z_edges, 12);
        apply(tmp_vertices, tmp_vertices, z_vertices, 8);
        transform(tmp_edges, tmp_vertices);
    }

    /* TODO we could combine rotations, but this is nicer code and it was fun and good practice */
    /* rotation around 6 diagonal for each 180 degrees */
    for (int i = 0; i < 6; ++i)
        transform(diagonal_180_edges[i], diagonal_180_vertices[i]);

    /* rotation around 4 diagonals, 120 degrees (2 for each diagonal) */
    for (int i = 0; i < 4; ++i) {
        init(tmp_edges, tmp_vertices);
        /* 120 degrees */
        apply(tmp_edges, tmp_edges, diagonal_120_edges[i], 12);
        apply(tmp_vertices, tmp_vertices, diagonal_120_vertices[i], 8);
        transform(tmp_edges, tmp_vertices);

        /* 240 degrees */
        apply(tmp_edges, tmp_edges, diagonal_120_edges[i], 12);
        apply(tmp_vertices, tmp_vertices, diagonal_120_vertices[i], 8);
        transform(tmp_edges, tmp_vertices);
    }

    /* print guard and includes */
    printf("#ifndef MC_TABLE_H\n");
    printf("#define MC_TABLE_H\n");
    printf("\n");
    printf("#include <stdint.h>\n");
    printf("\n\n");
    
    /* print main table with lists of edges */
    print_array2d("int8_t", "mc_edges", &table[0][0], 256, 16, "%2d");

    printf("\n\n");

    /* print table with surfaces, each encoded in 2 bytes [empty,id,end,start] */
    print_array2d("int16_t", "mc_in_edge2surface", &surface[0][0], 256, 36, "0x%04X");

    printf("\n\n");

    /* print table with out edges */
    print_array2d("int8_t", "mc_out_edges", &surface_edge[0][0], 256, 16, "%2d");

    printf("\n\n");
    
    /* print table with edges mapping to indices */
    print_array2d("int8_t", "mc_edge2indices", &edge2indices[0][0], 12, 2, "%d");

    printf("\n\n");

    /* print table with indices mapping to vertices */
    print_array2d("int8_t", "mc_index2vertex", &index2vertex[0][0], 8, 3, "%d");

    printf("\n\n");

    /* print table with in edges mapped to pair of cube edges */
    print_array2d("int8_t", "mc_out_edge2cell", &out2in[0][0], 36, 4, "%2d");



    printf("\n");
    printf("#endif\n");

    return 0;
}