Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 231 lines (209 sloc) 5.982 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
#include "io_cm.h"

int read_spinorfield_cm_single(spinor * const s, spinor * const r, char * filename,
const int ts, const int vol) {
  /*
* ts is the number of the timeslice to be used
* if ts < 0 read a volume source
*
* if ts >= 0 and vol > 0 the file is a volume file
* but only one timeslice should be read
*/

  FILE * ifs;
  int t, x, y , z, i = 0;
  spinor * p = NULL;
  float tmp[24];

  ifs = fopen(filename, "r");
  if(ifs == (FILE *)NULL) {
    return(-1);
  }

  for(x = 0; x < LX; x++) {
    for(y = 0; y < LY; y++) {
      for(z = 0; z < LZ; z++) {
#if (defined MPI)
fseek(ifs,
(g_proc_coords[0]*T+
(((g_proc_coords[1]*LX+x)*g_nproc_y*LY+g_proc_coords[2]*LY+y)*g_nproc_z*LZ
+ g_proc_coords[3]*LZ+z)*T*g_nproc_t)*sizeof(spinor)/2,
SEEK_SET);
#endif
for(t = 0; t < T; t++) {

i = g_lexic2eosub[ g_ipt[t][x][y][z] ];
if((t+x+y+z+
g_proc_coords[0]*T+g_proc_coords[1]*LX+
g_proc_coords[2]*LY+g_proc_coords[3]*LZ)%2==0) {
p = s;
}
else {
p = r;
}

if(ts == t || ts < 0 || ts >= T){
/* Read the data */
fread(tmp, sizeof(spinor)/2, 1, ifs);

            /* Test if we read the data with the correct endian order */
            if(isnan(tmp[0]) || isnan(tmp[1]) || isnan(tmp[2]) || isnan(tmp[3]) || isnan(tmp[4]) || isnan(tmp[5]) ||
            isnan(tmp[6]) || isnan(tmp[7]) || isnan(tmp[8]) || isnan(tmp[9]) || isnan(tmp[10]) || isnan(tmp[11]) ||
            isnan(tmp[12]) || isnan(tmp[13]) || isnan(tmp[14]) || isnan(tmp[15]) || isnan(tmp[16]) || isnan(tmp[17]) ||
            isnan(tmp[18]) || isnan(tmp[19]) || isnan(tmp[20]) || isnan(tmp[21]) || isnan(tmp[22]) || isnan(tmp[23]))
            {
              if(g_proc_id == 0)
              {
                if(big_endian())
                  printf("\nBig endian order gives some NaN. Trying little endian order instead...\n\n");
                else
                  printf("\nLittle endian order gives some NaN. Trying big endian order instead...\n\n");
              }

              fclose(ifs);
              return read_spinorfield_cm_swap_single(s,r,filename,ts,vol);
            }
single2double_cm(p+i, tmp);
}
else {
if(vol > 0) {
fread(tmp, sizeof(spinor)/2, 1, ifs);
}
/* Padding with zeros */
zero_spinor(p+i);
}
}
      }
    }
  }
  fclose(ifs);
  return(0);
}

int read_spinorfield_cm_swap_single(spinor * const s, spinor * const r, char * filename,
                               const int ts, const int vol) {
  /*
* ts is the number of the timeslice to be used
* if ts < 0 read a volume source
*
* if ts >= 0 and vol > 0 the file is a volume file
* but only one timeslice should be read
*/

  FILE * ifs;
  int t, x, y , z, i = 0;
  spinor * p = NULL;
  float tmp[24];

  ifs = fopen(filename, "r");
  if(ifs == (FILE *)NULL) {
    fprintf(stderr, "Could not open file %s\n Aborting...\n", filename);
#ifdef MPI
    MPI_Abort(MPI_COMM_WORLD, 1);
    MPI_Finalize();
#endif
    exit(500);
  }

  for(x = 0; x < LX; x++) {
    for(y = 0; y < LY; y++) {
      for(z = 0; z < LZ; z++) {
#if (defined MPI)
        fseek(ifs,
              (g_proc_coords[0]*T+
               (((g_proc_coords[1]*LX+x)*g_nproc_y*LY+g_proc_coords[2]*LY+y)*g_nproc_z*LZ
                + g_proc_coords[3]*LZ+z)*T*g_nproc_t)*sizeof(spinor)/2,
              SEEK_SET);
#endif
        for(t = 0; t < T; t++) {

          i = g_lexic2eosub[ g_ipt[t][x][y][z] ];
          if((t+x+y+z+
              g_proc_coords[0]*T+g_proc_coords[1]*LX+
              g_proc_coords[2]*LY+g_proc_coords[3]*LZ)%2==0) {
            p = s;
          }
          else {
            p = r;
          }

          if(ts == t || ts < 0 || ts >= T){
            /* Read the data */
            fread(tmp, sizeof(spinor)/2, 1, ifs);

            /* Swap and convert from single to double precision */
            be_to_cpu_assign_single2double(p+i, tmp, sizeof(spinor)/8);
          }
          else {
            if(vol > 0) {
              fread(tmp, sizeof(spinor)/2, 1, ifs);
            }
            /* Padding with zeros */
            zero_spinor(p+i);
          }
        }
      }
    }
  }
  fclose(ifs);
  return(0);
}


int write_spinorfield_cm_single(spinor * const s, spinor * const r, char * filename) {

  FILE * ofs = NULL;
  int t, x, y , z, i = 0;
  int t0, X, Y, Z, id = 0;
  spinor * p = NULL;
  float tmp[24];
  int coords[4];
#ifdef MPI
  int tag = 0;
  MPI_Status status;
#endif
  
  if(g_cart_id == 0) {
    ofs = fopen(filename, "w");
    printf("# Writing in cmi format (32 Bit) to file %s\n", filename);
  }

  for(x = 0; x < LX*g_nproc_x; x++) {
    X = x - LX*g_proc_coords[1];
    coords[1] = x / LX;
    for(y = 0; y < LY*g_nproc_y; y++) {
      Y = y - LY*g_proc_coords[2];
      coords[2] = y / LY;
      for(z = 0; z < LZ*g_nproc_z; z++) {
Z = z - LZ*g_proc_coords[3];
coords[3] = z / LZ;
for(t0 = 0; t0 < T*g_nproc_t; t0++) {
t = t0 - T*g_proc_coords[0];
coords[0] = t0 / T;
#ifdef MPI
MPI_Cart_rank(g_cart_grid, coords, &id);
#endif
if(g_cart_id == id) {
i = g_lexic2eosub[ g_ipt[t][X][Y][Z] ];
if((t+X+Y+Z+g_proc_coords[3]*LZ+g_proc_coords[2]*LY
+ g_proc_coords[0]*T+g_proc_coords[1]*LX)%2 == 0) {
p = s;
}
else {
p = r;
}
}
if(g_cart_id == 0){
if(g_cart_id == id) {
double2single_cm(tmp, p + i);
}
#ifdef MPI
else {
MPI_Recv(tmp, sizeof(spinor)/8, MPI_FLOAT, id, tag, g_cart_grid, &status);
}
#endif
fwrite(tmp, sizeof(float), 24, ofs);
// printf("%e,%e\n",tmp[0],tmp[5]);fflush(stdout);
}
#ifdef MPI
else {
if(g_cart_id == id) {
double2single_cm(tmp, p + i);
MPI_Send((void*) tmp, sizeof(spinor)/8, MPI_FLOAT, 0, tag, g_cart_grid);
}
}
tag++;
#endif
}
#ifdef MPI
MPI_Barrier(g_cart_grid);
tag=0;
#endif
      }
    }
  }
  if(g_cart_id == 0) {
    fclose(ofs);
  }
  return(0);
}

Something went wrong with that request. Please try again.