Exemplo n.º 1
0
extern "C" void FTN(c_esmc_regrid_getiwts)(ESMCI::VM **vmpp, Grid **gridpp,
                   Mesh **meshpp, ESMCI::Array **arraypp, int *staggerLoc,
                   int *regridScheme, int*rc) {
#undef  ESMC_METHOD
#define ESMC_METHOD "c_esmc_regrid_getiwts()" 
  Trace __trace(" FTN(regrid_getiwts)()");
  ESMCI::VM *vm = *vmpp;
  ESMCI::Array &array = **arraypp;

  int localPet = vm->getLocalPet();
  int petCount = vm->getPetCount();

  Mesh &mesh = **meshpp;
  Grid &grid = **gridpp;

  try {

    // Get the integration weights
    MEField<> *iwts = mesh.GetField("iwts");
    if (!iwts) Throw() << "Could not find integration weights field on this mesh"
                             <<std::endl; 

    if(!get_iwts(mesh, iwts, regridScheme))
      Throw() << "Online regridding error" << std::endl;
    
    CpMeshDataToArray(grid, *staggerLoc, mesh, array, iwts);
 
  } catch(std::exception &x) {
    // catch Mesh exception return code 
    if (x.what()) {
      ESMC_LogDefault.ESMC_LogMsgFoundError(ESMC_RC_INTNRL_BAD,
   					  x.what(), rc);
    } else {
      ESMC_LogDefault.ESMC_LogMsgFoundError(ESMC_RC_INTNRL_BAD,
   					  "UNKNOWN", rc);
    }

    return;
  } catch(int localrc){
    // catch standard ESMF return code
    ESMC_LogDefault.ESMC_LogMsgFoundError(localrc, ESMF_ERR_PASSTHRU, rc);
    return;
  } catch(...){
    ESMC_LogDefault.ESMC_LogMsgFoundError(ESMC_RC_INTNRL_BAD,
      "- Caught unknown exception", rc);
    return;
  }

  // Set return code 
  if (rc!=NULL) *rc = ESMF_SUCCESS;

}
Exemplo n.º 2
0
int ESMC_VMGet(ESMC_VM vm, int *localPet, int *petCount, int *peCount,
  MPI_Comm *mpiCommunicator, int *pthreadsEnabledFlag, int *openMPEnabledFlag){
#undef  ESMC_METHOD
#define ESMC_METHOD "ESMC_VMGet()"

  // initialize return code; assume routine not implemented
  int rc = ESMC_RC_NOT_IMPL;              // final return code

  ESMCI::VM *vmp = (ESMCI::VM*)(vm.ptr);

  *localPet = vmp->getLocalPet();
  *petCount = vmp->getPetCount();

  //compute peCount
  int npets = vmp->getNpets();
  *peCount = 0; // reset
  for (int i=0; i<npets; i++)
    *peCount += vmp->getNcpet(i);

  *mpiCommunicator = vmp->getMpi_c();
  *pthreadsEnabledFlag = vmp->isPthreadsEnabled();
  *openMPEnabledFlag = vmp->isOpenMPEnabled();

  // return successfully
  rc = ESMF_SUCCESS;
  return rc;
}
Exemplo n.º 3
0
int ESMC_VMPrint(ESMC_VM vm){
#undef  ESMC_METHOD
#define ESMC_METHOD "ESMC_VMPrint()"

  // initialize return code; assume routine not implemented
  int localrc = ESMC_RC_NOT_IMPL;         // local return code
  int rc = ESMC_RC_NOT_IMPL;              // final return code
  
  // typecast into ESMCI type
  ESMCI::VM *vmp = (ESMCI::VM *)(vm.ptr);

  // call into ESMCI method  
  localrc = vmp->print();
  if (ESMC_LogDefault.MsgFoundError(localrc, ESMF_ERR_PASSTHRU, &rc))
    return rc;  // bail out
    
  // return successfully
  rc = ESMF_SUCCESS;
  return rc;
}  
Exemplo n.º 4
0
extern "C" void FTN(c_esmc_regrid_create)(ESMCI::VM **vmpp,
                   Mesh **meshsrcpp, ESMCI::Array **arraysrcpp, int *srcstaggerLoc,
                   Mesh **meshdstpp, ESMCI::Array **arraydstpp, int *dststaggerLoc,
		   int *regridMethod, int *regridConserve, 
                   int *regridScheme, int *unmappedaction,
                   ESMCI::RouteHandle **rh, int *has_rh, int *has_iw,
                   int *nentries, ESMCI::TempWeights **tweights,
                   int*rc) {
#undef  ESMC_METHOD
#define ESMC_METHOD "c_esmc_regrid_create()" 
  Trace __trace(" FTN(regrid_test)(ESMCI::VM **vmpp, ESMCI::Grid **gridsrcpp, int *srcstaggerLoc, ESMCI::Grid **griddstcpp, int *dststaggerLoc, int*rc");
  ESMCI::VM *vm = *vmpp;
  ESMCI::Array &srcarray = **arraysrcpp;
  ESMCI::Array &dstarray = **arraydstpp;

  int localPet = vm->getLocalPet();
  int petCount = vm->getPetCount();

  Mesh &srcmesh = **meshsrcpp;
  Mesh &dstmesh = **meshdstpp;

  try {

    // Weights matrix
    IWeights wts;

    if(!online_regrid(srcmesh, dstmesh, wts, regridConserve, regridMethod,
                      regridScheme, unmappedaction))
      Throw() << "Online regridding error" << std::endl;

    //wts.Print(Par::Out());

    // We have the weights, now set up the sparsemm object

    // Firstly, the index list
    std::pair<UInt,UInt> iisize = wts.count_matrix_entries();
    int num_entries = iisize.first;
    int *iientries = new int[2*iisize.first]; 
    int larg[2] = {2, iisize.first};
    // Gather the list
    ESMCI::InterfaceInt ii(iientries, 2, larg);
    ESMCI::InterfaceInt *iiptr = &ii;

    double *factors = new double[iisize.first];

    // Gather the data
    WMat::WeightMap::iterator wi = wts.begin_row(), we = wts.end_row();

    UInt i = 0;
    for (; wi != we; ++wi) {
      const WMat::Entry &w = wi->first;


      std::vector<WMat::Entry> &wcol = wi->second;

      for (UInt j = 0; j < wcol.size(); ++j) {

        UInt twoi = 2*i;

        const WMat::Entry &wc = wcol[j];

        // I expected things to be (dst,src), but they are (src_id,dst_id)
        //iientries[twoi] = w.id;  iientries[twoi+1] = wc.id;
        iientries[twoi+1] = w.id;  iientries[twoi] = wc.id;
        
        factors[i] = wc.value;

        i++;

      } // for j
      

    } // for wi

/*
Par::Out() << "Matrix entries" << std::endl;
for (UInt n = 0; n < num_entries; ++n) {
  Par::Out() << std::setw(5) << iientries[2*n] << std::setw(5) << iientries[2*n+1] << std::setw(15) << factors[n] << std::endl;
}
wts.Print(Par::Out());
*/

    // Build the ArraySMM
    if (*has_rh != 0) {
      int localrc;
      enum ESMC_TypeKind tk = ESMC_TYPEKIND_R8;
      FTN(c_esmc_arraysmmstore)(arraysrcpp, arraydstpp, rh, &tk, factors,
                 &num_entries, &iiptr, &localrc);
      if (ESMC_LogDefault.ESMC_LogMsgFoundError(localrc,ESMF_ERR_PASSTHRU,NULL))
	throw localrc;  // bail out with exception
    }

    *nentries = num_entries;
    // Clean up.  If has_iw, then we will use the arrays to
    // fill out the users pointers.  These will be deleted following a copy.
    if (*has_iw == 0) {
      delete [] factors;
      delete [] iientries;
      *nentries = 0;
    } else {
      // Save off the weights so the F90 caller can allocate arrays and
      // copy the values.
      *tweights = new ESMCI::TempWeights;
      (*tweights)->nentries = num_entries;
      (*tweights)->factors = factors;
      (*tweights)->iientries = iientries;
    }
    
  } catch(std::exception &x) {
    // catch Mesh exception return code 
    if (x.what()) {
      ESMC_LogDefault.ESMC_LogMsgFoundError(ESMC_RC_INTNRL_BAD,
   					  x.what(), rc);
    } else {
      ESMC_LogDefault.ESMC_LogMsgFoundError(ESMC_RC_INTNRL_BAD,
   					  "UNKNOWN", rc);
    }

    return;
  } catch(int localrc){
    // catch standard ESMF return code
    ESMC_LogDefault.ESMC_LogMsgFoundError(localrc, ESMF_ERR_PASSTHRU, rc);
    return;
  } catch(...){
    ESMC_LogDefault.ESMC_LogMsgFoundError(ESMC_RC_INTNRL_BAD,
      "- Caught unknown exception", rc);
    return;
  }

  // Set return code 
  if (rc!=NULL) *rc = ESMF_SUCCESS;

}
Exemplo n.º 5
0
//-----------------------------------------------------------------------------
//BOP
// !IROUTINE:  ESMCI::TestStart() - Initialize the framework, print a standard msg
//
// !INTERFACE:   
int TestStart(
//
// !RETURN VALUE:
//    ESMF_SUCCESS or ESMF_FAILURE
//
// !ARGUMENTS:
  const char *file, // in - test filename
  int line,         // in - test line number in test filename
  int only) {       // in - if set to 0, print on stderr also
// 
// !DESCRIPTION:
//    Initializes the framework, prints out the standard messages needed
//    by the testing scripts.
//    If {\tt only} is zero, also print same message to stderr as well
//    as the normal output on stdout.  The default for {\tt only} is 1.
//
//EOP
//-----------------------------------------------------------------------------
  int rc;
  ESMCI::VM *globalVM;
  char msgbuf[ESMF_MAXSTR], failMsg[ESMF_MAXSTR];
  int numPETs;
  ESMCI::LogErr *whichLog;

  // TODO: this should be settable by the user
  whichLog = &ESMC_LogDefault;

  if (file == NULL) {
    sprintf(msgbuf, "FAIL %s, line %d, null filename passed to "
      "ESMCI::TestStart()\n", __FILE__, __LINE__);
    whichLog->Write(msgbuf, ESMC_LOG_INFO);
    if (!only)
      fprintf(stderr, "%s", msgbuf);
    return(ESMF_FAILURE);
  }

  char logFileName[160];
  const char *underScore = strchr(file, '_');
  if (underScore == NULL) underScore = file-1;
  const char *period = strrchr(file, '.');
  int numChars = period - underScore;
  strncpy(logFileName, underScore+1, numChars);
  strcpy(logFileName+numChars, "Log\0");

  rc = ESMCI_Initialize((char *)"", ESMC_CAL_NOCALENDAR, logFileName,
    ESMC_LOG_MULTI);
  if (rc != ESMF_SUCCESS) {
    sprintf(msgbuf, "FAIL  rc=%d, %s, line %d, Unable to initialize ESMF\n", rc,
      file, line);
    whichLog->Write(msgbuf, ESMC_LOG_INFO);
    if (!only)
      fprintf(stderr, "%s", msgbuf);
    return(rc);
  }

  globalVM = ESMCI::VM::getGlobal(&rc);
  if ((globalVM == NULL) || (rc != ESMF_SUCCESS)) {
    sprintf(msgbuf, "FAIL  rc=%d, %s, line %d, Unable to get GlobalVM\n", rc,
      file, line);

    whichLog->Write(msgbuf, ESMC_LOG_INFO);
    if (!only)
      fprintf(stderr, "%s", msgbuf);

    return (false);
  }

  numPETs = globalVM->getPetCount();

  sprintf(msgbuf, "Beginning Test, file %s, line %d\n", file, line);
  whichLog->Write(msgbuf, ESMC_LOG_INFO);
  if (!only)
    fprintf(stderr, "%s", msgbuf);

  sprintf(msgbuf, "NUMBER_OF_PROCESSORS %d\n", numPETs);
  whichLog->Write(msgbuf, ESMC_LOG_INFO);
  if (!only)
    fprintf(stderr, "%s", msgbuf);
 
  return(ESMF_SUCCESS);

} // end ESMC_TestStart
Exemplo n.º 6
0
//-----------------------------------------------------------------------------
//BOP
// !IROUTINE:  ESMCI::TestNumPETs() - Verify there are exactly this number of PETs
//
// !INTERFACE:   
bool TestNumPETs(
//
// !RETURN VALUE:
//    true or false
//
// !ARGUMENTS:
  int petCount,   // in - the exact acceptable number of PETs
  char *file,     // in - test filename
  int line,       // in - test line number in test filename
  int only) {     // in - if set to 0, print on stderr also
// 
// !DESCRIPTION:
//    Returns true only if there are exactly the number of requested PETs.
//    If {\tt only} is zero, also print same message to stderr as well
//    as the normal output on stdout.  The default for {\tt only} is 1.
//
//EOP
//-----------------------------------------------------------------------------
  int rc;
  ESMCI::VM *globalVM;
  char msgbuf[ESMF_MAXSTR], failMsg[ESMF_MAXSTR];
  int numPETs;
  ESMCI::LogErr *whichLog;

  // TODO: this should be settable by the user
  whichLog = &ESMC_LogDefault;

  if (file == NULL) {
    sprintf(msgbuf, "FAIL %s, line %d, null filename passed to "
      "ESMCI::TestNumPETs()\n", __FILE__, __LINE__);
    whichLog->Write(msgbuf, ESMC_LOG_INFO);
    if (!only)
      fprintf(stderr, "%s", msgbuf);
    return (false);
  }

  globalVM = ESMCI::VM::getGlobal(&rc);
  if ((globalVM == NULL) || (rc != ESMF_SUCCESS)) {
    sprintf(msgbuf, "FAIL  rc=%d, %s, line %d, Unable to get GlobalVM\n", rc,
      file, line);

    whichLog->Write(msgbuf, ESMC_LOG_INFO);
    if (!only)
      fprintf(stderr, "%s", msgbuf);

    return (false);
  }

  numPETs = globalVM->getPetCount();

  if (numPETs != petCount) {
    sprintf(failMsg, "These tests must run on exactly %d processors.\n", 
                    petCount);
    sprintf(msgbuf, "SKIP  %s, %s, line %d\n", failMsg, file, line);
    whichLog->Write(msgbuf, ESMC_LOG_INFO);
    if (!only)
      fprintf(stderr, "%s", msgbuf);

    return (false);
  }

  return (true);

}