Changeset da4244 for pcp/src/output.c


Ignore:
Timestamp:
Apr 21, 2008, 8:27:24 PM (17 years ago)
Author:
Frederik Heber <heber@…>
Children:
0b638d
Parents:
18d065
Message:

ReadSrcIons(): Process 0 reads and Bcasts to all others

MPI_Bcast is used by process 0 after parsing ion file alone to spread info to all other processes. Also flag tells other processes whether error occured or not before Bcasting of actual data.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pcp/src/output.c

    r18d065 rda4244  
    13501350  FILE *SrcIonDoc, *SrcIonData;
    13511351  char *suffix;
     1352  int flag = 0;
    13521353  // read the doc file and check
    1353   suffix = (char *)
    1354     Malloc(strlen(suffixsrciondoc) + 3 + 1,"ReadSrcIons: suffix");
    1355   sprintf(suffix, ".L%i%s", P->Lat.Lev[STANDARTLEVEL].LevelNo, suffixsrciondoc);
    1356   if (OpenFile(P, &SrcIonDoc, suffix, "r",P->Call.out[ReadOut])) {
    1357     if (fscanf(SrcIonDoc,"%i", &Max_Types) != 1) {
    1358       //Error(SomeError, "ReadSrcIons: read error");
    1359       Free(suffix, "ReadSrcIons: suffix");
    1360       return 0;
    1361     }
    1362     if (Max_Types != I->Max_Types) {
    1363       //Error(SomeError, "ReadSrcIons: srcion file does not fit to system, MaxTypes");
    1364       Free(suffix, "ReadSrcIons: suffix");
    1365       return 0;
    1366     }
    1367     Max_IonsOfType = (int *) Malloc(Max_Types*sizeof(int), "ReadSrcIons: Max_IonsOfType");
    1368     for (is=0; is < Max_Types; is++) {
    1369       if (fscanf(SrcIonDoc,"%i", &Max_IonsOfType[is]) != 1) {
    1370         //Error(SomeError, "ReadSrcIons: read error");
    1371         Free(suffix, "ReadSrcIons: suffix");
    1372           return 0;
    1373       }
    1374       if (Max_IonsOfType[is] != I->I[is].Max_IonsOfType) {
    1375         //Error(SomeError, "ReadSrcIons: srcion file does not fit to system, Max_IonsOfType");
    1376         Free(suffix, "ReadSrcIons: suffix");
    1377             return 0;
     1354
     1355  if (!P->Par.me) { // process 0 reads and broadcasts ..
     1356          suffix = (char *)
     1357          Malloc(strlen(suffixsrciondoc) + 3 + 1,"ReadSrcIons: suffix");
     1358          sprintf(suffix, ".L%i%s", P->Lat.Lev[STANDARTLEVEL].LevelNo, suffixsrciondoc);
     1359        if (OpenFile(P, &SrcIonDoc, suffix, "r",P->Call.out[ReadOut])) {
     1360        if (fscanf(SrcIonDoc,"%i", &Max_Types) != 1) {
     1361        //Error(SomeError, "ReadSrcIons: read error");
     1362              Free(suffix, "ReadSrcIons: suffix");
     1363        if (MPI_Bcast(&flag,1,MPI_INT,0,P->Par.comm) != MPI_SUCCESS)
     1364          Error(SomeError,"ReadSrcIons: Bcast of signal failed\n");
     1365        return flag;
    13781366            }
    1379     }
    1380     fclose(SrcIonDoc);
    1381     // read basis, then positions and speeds of ions
     1367          if (Max_Types != I->Max_Types) {
     1368          //Error(SomeError, "ReadSrcIons: srcion file does not fit to system, MaxTypes");
     1369              Free(suffix, "ReadSrcIons: suffix");
     1370        if (MPI_Bcast(&flag,1,MPI_INT,0,P->Par.comm) != MPI_SUCCESS)
     1371          Error(SomeError,"ReadSrcIons: Bcast of signal failed\n");
     1372        return flag;
     1373            }
     1374          Max_IonsOfType = (int *) Malloc(Max_Types*sizeof(int), "ReadSrcIons: Max_IonsOfType");
     1375          for (is=0; is < Max_Types; is++) {
     1376              if (fscanf(SrcIonDoc,"%i", &Max_IonsOfType[is]) != 1) {
     1377              //Error(SomeError, "ReadSrcIons: read error");
     1378            Free(suffix, "ReadSrcIons: suffix");
     1379          Free(Max_IonsOfType, "ReadSrcIons: Max_IonsOfType");
     1380          if (MPI_Bcast(&flag,1,MPI_INT,0,P->Par.comm) != MPI_SUCCESS)
     1381            Error(SomeError,"ReadSrcIons: Bcast of signal failed\n");
     1382          return flag;
     1383        }
     1384        if (Max_IonsOfType[is] != I->I[is].Max_IonsOfType) {
     1385            //Error(SomeError, "ReadSrcIons: srcion file does not fit to system, Max_IonsOfType");
     1386          Free(suffix, "ReadSrcIons: suffix");
     1387          Free(Max_IonsOfType, "ReadSrcIons: Max_IonsOfType");
     1388          if (MPI_Bcast(&flag,1,MPI_INT,0,P->Par.comm) != MPI_SUCCESS)
     1389            Error(SomeError,"ReadSrcIons: Bcast of signal failed\n");
     1390          return flag;
     1391                    }
     1392            }
     1393      Free(Max_IonsOfType, "ReadSrcIons: Max_IonsOfType");
     1394            fclose(SrcIonDoc);
     1395        }
     1396          // read basis, then positions and speeds of ions
    13821397    if (OpenFile(P, &SrcIonData, suffixsrciondat, "rb",P->Call.out[ReadOut])) {
    13831398      if (fread(RealBasis, sizeof(double), (size_t)(NDIM_NDIM), SrcIonData) != NDIM_NDIM) {
    13841399        //Error(SomeError, "ReadSrcIons: read error");
    13851400        Free(suffix, "ReadSrcIons: suffix");
    1386         return 0;
     1401        if (MPI_Bcast(&flag,1,MPI_INT,0,P->Par.comm) != MPI_SUCCESS)
     1402          Error(SomeError,"ReadSrcIons: Bcast of signal failed\n");
     1403        return flag;
    13871404      }
    13881405      for (i=0; i < NDIM_NDIM; i++)
    13891406        if (RealBasis[i] != P->Lat.RealBasis[i]) {
    13901407          //Error(SomeError, "ReadSrcIons: srcion file does not fit to system, RealBasis");
    1391                 Free(suffix, "ReadSrcIons: suffix");
    1392           return 0;
     1408          Free(suffix, "ReadSrcIons: suffix");
     1409          if (MPI_Bcast(&flag,1,MPI_INT,0,P->Par.comm) != MPI_SUCCESS)
     1410            Error(SomeError,"ReadSrcIons: Bcast of signal failed\n");
     1411          return flag;
    13931412        }
    13941413      for (is=0; is < I->Max_Types; is++) {
     
    13961415          if (fread(&data, sizeof(double), (size_t)(2*NDIM), SrcIonData) != 2*NDIM) {
    13971416                //Error(SomeError, "ReadSrcIons: read error");
    1398                         Free(suffix, "ReadSrcIons: suffix");
    1399             return 0;
     1417            Free(suffix, "ReadSrcIons: suffix");
     1418            if (MPI_Bcast(&flag,1,MPI_INT,0,P->Par.comm) != MPI_SUCCESS)
     1419              Error(SomeError,"ReadSrcIons: Bcast of signal failed\n");
     1420            return flag;
    14001421          }
    14011422          U = &I->I[is].U[NDIM*ia];
     
    14081429      }
    14091430      fclose(SrcIonData);
    1410     }
    1411     if (Max_IonsOfType != NULL) Free(Max_IonsOfType, "Max_IonsOfType");
    1412   }
     1431      flag = 1;
     1432    }
    14131433    Free(suffix, "ReadSrcIons: suffix");
    1414   return 1;
     1434  }
     1435  if (MPI_Bcast(&flag,1,MPI_INT,0,P->Par.comm) != MPI_SUCCESS)
     1436    Error(SomeError,"ReadSrcIons: Bcast of signal failed\n");
     1437  //fprintf(stderr, "(%i) Flag is %i\n", P->Par.me, flag);
     1438  if (flag) {
     1439    for (is=0; is < I->Max_Types; is++) {
     1440      if (MPI_Bcast(I->I[is].R, I->I[is].Max_IonsOfType*NDIM, MPI_DOUBLE, 0, P->Par.comm) != MPI_SUCCESS)
     1441        Error(SomeError,"ReadSrcIons: Bcast of I->I[is].R failed\n");       
     1442      if (MPI_Bcast(I->I[is].U, I->I[is].Max_IonsOfType*NDIM, MPI_DOUBLE, 0, P->Par.comm) != MPI_SUCCESS)
     1443        Error(SomeError,"ReadSrcIons: Bcast of I->I[is].U failed\n");
     1444    }
     1445  }
     1446  //fprintf(stderr, "(%i) ReadSrcIons done\n", P->Par.me);
     1447  return flag;
    14151448}
    14161449
Note: See TracChangeset for help on using the changeset viewer.