33
33
34
34
#define TRUE 1
35
35
#define FALSE 0
36
- #define M 64
37
- #define N 64
36
+ #define M 16
37
+ #define N 16
38
38
#define M_LEN (M + 1)
39
39
#define N_LEN (N + 1)
40
40
#define SIZE ((M_LEN)*(N_LEN))
41
- #define ITMAX 4000
41
+ #define ITMAX 1
42
42
#define L_OUT TRUE
43
43
#define VAL_OUT TRUE
44
44
45
45
extern double wtime ();
46
46
extern void dswap (double * * a , double * * b );
47
47
extern void write_to_file (double * array , int tM , int tN , char * filename );
48
+ extern void print_to_file (double * array , int tM , int tN , char * filename );
48
49
49
50
//! Benchmark weather prediction program for comparing the
50
51
//! preformance of current supercomputers. The model is
@@ -363,9 +364,12 @@ int main(int argc, char **argv) {
363
364
364
365
// Output p, u, v fields and run times.
365
366
if (VAL_OUT ){
366
- write_to_file (pnew , M_LEN , N_LEN , "p.txt" );
367
- write_to_file (unew , M_LEN , N_LEN , "u.txt" );
368
- write_to_file (vnew , M_LEN , N_LEN , "v.txt" );
367
+ write_to_file (pnew , M_LEN , N_LEN , "p.bin" );
368
+ write_to_file (unew , M_LEN , N_LEN , "u.bin" );
369
+ write_to_file (vnew , M_LEN , N_LEN , "v.bin" );
370
+ print_to_file (pnew , M_LEN , N_LEN , "p.txt" );
371
+ print_to_file (unew , M_LEN , N_LEN , "u.txt" );
372
+ print_to_file (vnew , M_LEN , N_LEN , "v.txt" );
369
373
}
370
374
371
375
if (L_OUT ) {
@@ -431,7 +435,7 @@ void dswap(double **pA, double **pB)
431
435
* pB = pTemp ;
432
436
}
433
437
434
- void write_to_file (double * array , int tM , int tN , char * filename ) {
438
+ void print_to_file (double * array , int tM , int tN , char * filename ) {
435
439
FILE * file = fopen (filename , "w" );
436
440
if (file == NULL ) {
437
441
printf ("Error opening file %s\n" , filename );
@@ -445,3 +449,18 @@ void write_to_file(double *array, int tM, int tN, char *filename) {
445
449
}
446
450
fclose (file );
447
451
}
452
+
453
+ void write_to_file (double * array , int tM , int tN , char * filename ) {
454
+ FILE * file = fopen (filename , "wb" );
455
+ if (file == NULL ) {
456
+ printf ("Error opening file %s\n" , filename );
457
+ return ;
458
+ }
459
+ for (int i = 0 ; i < tM ; i ++ ) {
460
+ for (int j = 0 ; j < tN ; j ++ ) {
461
+ fwrite (& array [(i * (tN ))+ j ], sizeof (double ), 1 , file );
462
+ }
463
+ fprintf (file , "\n" );
464
+ }
465
+ fclose (file );
466
+ }
0 commit comments