VOID CFileObject::OnDestroy(_In_ WDFOBJECT FileObject)
{
    FunctionEntry("...");

    CFileObject *pFileObject = GetFileObject(FileObject);

    NT_ASSERT(pFileObject != nullptr);

    if (pFileObject->m_FileObject == FileObject) {
        // File object constructed using placement 'new' so explicitly invoke destructor
        pFileObject->~CFileObject();
    }

    FunctionReturnVoid();
}
Ejemplo n.º 2
0
void FunctionManager::registerFunction(const Common::UString &name, uint32 id,
                                       const Function &func, const Signature &signature,
                                       const Parameters &defaults) {

	std::pair<FunctionMap::iterator, bool> result;

	result = _functionMap.insert(std::make_pair(name, FunctionEntry(name)));
	if (!result.second)
		throw Common::Exception("Failed to register NWScript function \"%s\"", name.c_str());

	FunctionEntry &f = result.first->second;

	f.func = func;
	f.ctx.setSignature(signature);
	f.ctx.setDefaults(defaults);
	f.empty = false;

	if (_functionArray.size() <= id)
		_functionArray.resize(id + 1);

	_functionArray[id] = f;
}
Ejemplo n.º 3
0
  int SerialProgram::ConnectivityMaps(SolverUtils::Mesh::Connectivity nodesToElems){

      std::ostringstream Ostr;
      std::stringstream ss;

      FunctionEntry("ConnectivityMaps");

      std::cout << "In ConnectivityMaps function" << std::endl;

      //resize nodeToNode map
      nodeToNode.resize(numNodes);

      int elem, node;

      //Generate node to node map
      //loop over every node
      for(int i=0; i < numNodes; i++){
        std::cout << "node " << i+1 << ":" << std::endl;
        //loop over every element for that node
        for(int j=0; j < nodesToElems[i].size(); j++){
          std::cout << "element " << nodesToElems[i][j] << ":" << std::endl;
          elem = nodesToElems[i][j]-1;
          //loop over every node for that element
          for(int k=0; k < numNodesPerElem; k++){
            node = elems[numNodesPerElem*elem + k];
            //don't add the node to its own list
            if(node == i+1)
              continue;
            //loop over all the entries for the nodeToNode map and
            //see if this node has been added yet
            bool newValue=true;
            for(int l=0; l < nodeToNode[i].size(); l++){
              if(node == nodeToNode[i][l]){
                newValue=false;
                break;
              }
            }
            //if its a new value add it
            if(newValue){
              nodeToNode[i].push_back(node);
            }
          }
        }//element around node loop
      }//node lope

      //print nodeToNode to check
      if(verblevel > 3){
        Ostr << "Node to node map:" << std::endl;
        for(int i=0; i < nodeToNode.size(); i++){
          Ostr << i+1 << ":" << std::endl;
          for(int j=0; j < nodeToNode[i].size(); j++){
            Ostr << nodeToNode[i][j] << " ";
          }
          Ostr << std::endl;
        }
      }

      //Generate list of element edges from node to node map
      //loop over every node
      numNodesPerElemEdge = 2;
      numElemEdges = 0;
      for(int i=0; i < numNodes; i++){
        //loop over every node connected to that node
        for(int j=0; j < nodeToNode[i].size(); j++){
          node = nodeToNode[i][j];
          //if the node # is greater than the current node then it
          //hasn't been processed yet so its a new edge
          if(node > i+1){
            elemEdges.push_back(i+1);
            elemEdges.push_back(node);
            numElemEdges++;
          }
        }//nodes around node loop
      }//node loop      

      //print nodeToNode to check
      if(verblevel > 3){
        Ostr << "Element edges:" << std::endl;
        for(int i=0; i < numElemEdges; i++){
          Ostr << i+1 << ":" << std::endl;
          for(int j=0; j < numNodesPerElemEdge; j++){
            Ostr << elemEdges[i*numNodesPerElemEdge + j] << " ";
          }
          Ostr << std::endl;
        }
      }

      //Genereate a map from elements to element edges
      numEdgesPerElem = 6; //Everything is pretty much hard coded
                           //for linear tets right now
      //loop over every element
      for(int i=0; i < numElems; i++){
        //loop over every node for the element
        for(int j=0; j < numNodesPerElem; j++){
          int n1, n2;
          n1 = elems[i*numNodesPerElem + j];
          //loop over every other node for the element
          for(int k=j+1; k < numNodesPerElem; k++){   
            n2 = elems[i*numNodesPerElem + k];
            //loop over every element edge to find what edge 
            //these two nodes are
            for(int l=0; l < numElemEdges; l++){
              if(n1 == elemEdges[l*numNodesPerElemEdge] &&
                 n2 == elemEdges[l*numNodesPerElemEdge + 1])
                elemToElemEdges.push_back(l+1);         
              else if(n2 == elemEdges[l*numNodesPerElemEdge] &&
                 n1 == elemEdges[l*numNodesPerElemEdge + 1])
                elemToElemEdges.push_back(l+1);         
            }//loop over every element edge
          }//loop over every other node for the element
        }//loop over every node for the element
      }//loop over every element

      //print elemToElemEdges to check
      if(verblevel > 3){
        Ostr << "Element to element edges:" << std::endl;
        for(int i=0; i < numElems; i++){
          Ostr << i+1 << ":" << std::endl;
          for(int j=0; j < numEdgesPerElem; j++){
            Ostr << elemToElemEdges[i*numEdgesPerElem + j] << " ";
          }
          Ostr << std::endl;
        }
      }

      StdOut(Ostr.str());
      Ostr.str("");

      FunctionExit("ConnectivityMaps");

    return 0;
 
  } //HigherOrderTets function
    int SerialProgram::Run()
    {
      // FunctionEntry("NAME"): Updates the user-defined stack and 
      // the program profiles with timing information. The placement
      // of FunctionEntry and FunctionExit calls is at the developer's
      // discretion.  
      FunctionEntry("Run");

      // ---------- The Program -----------------
      // This program just "copies" the input file
      // to the output file.
      //

      // Open the specified input file for reading
      Inf.open(input_name.c_str());
      if(!Inf){
        // If the input file failed to open, notify to
        // the error stream and return non-zero
        std::ostringstream Ostr;
        Ostr << "SerialProgram:Run: Error: Could not output input file, " 
             << input_name << ".";
        ErrOut(Ostr.str());
        // don't forget to tell the profiler/stacker the
        // function is exiting.
        FunctionExit("Run");
        return(1);
      }

      // Open the specified output file for writing
      bool use_outfile = false;
      if(!output_name.empty()){
        use_outfile = true;
        Ouf.open(output_name.c_str());
        if(!Ouf){
          // If the output file failed to open, notify
          // to error stream and return non-zero
          std::ostringstream Ostr;
          Ostr << "SerialProgram:Run: Error: Unable to open output file, " << output_name << ".";
          ErrOut(Ostr.str());
          // don't forget to tell the profiler/stacker the
          // function is exiting.
          FunctionExit("Run");
          return(1);
        }
      }

      // Read lines from the input file and repeat them 
      // to the output file.
      std::string line;
      while(std::getline(Inf,line)){
        if(use_outfile)
          Ouf << line << std::endl;
        else
          StdOut(line+"\n");
      }
      // Close both files
      Ouf.close();
      Inf.close();
      
      //
      // ---------- Program End -----------------


      // Update the stacker/profiler that we are exiting 
      // this function.
      FunctionExit("Run");
      // return 0 for success
      return(0);
    };
Ejemplo n.º 5
0
    int ParallelProgram::Run()
    {
      // FunctionEntry("NAME"): Updates the user-defined stack and 
      // the program profiles with timing information.  The placement
      // of FunctionEntry and FunctionExit calls is at the developer's
      // discretion.  
      FunctionEntry("Run");

      int myid  = _communicator.Rank();
      int nproc = _communicator.Size();
      bool use_file = !output_name.empty();

      // Put out a quick blurb about number of procs just
      // to give the user confidence we are actually running
      // in parallel.  Note that when using the "StdOut" method
      // that it automatically does output only on rank 0. If 
      // the developer wants asyncrhonous output, then they 
      // have to revert to using standard streams.
      std::ostringstream RepStr;
      if(verblevel > 1)
        RepStr << "Running on " << nproc << " processors." << std::endl;
      StdOut(RepStr.str());
      _communicator.Barrier();
      if(verblevel > 1)
        StdOut("All procesors ready.\n");

      // Open the specified output file for writing on rank 0
      if(use_file && !myid){
        Ouf.open(output_name.c_str(),std::ios::app);
        if(!Ouf){
          // If the output file failed to open, notify
          // to error stream and return non-zero
          std::ostringstream Ostr;
          Ostr << "Error: Unable to open output file, " << output_name << ".";
          ErrOut(Ostr.str());
          // In parallel, we don't return right away since 
          // this part of the code is only done on proc 0.
          // Instead, the error value is set in the communicator
          // which will indicate to all processors that there 
          // has been some error.
          _communicator.SetExit(1);
        }
      }
      // Check to see if an error condition was set 
      // in the file open block above.  If so, then
      // return with an error code.
      if(_communicator.Check()){
          // don't forget to tell the profiler/stacker the
          // function is exiting.
          FunctionExit("Run");
          return(1);
      }
        
      // Correct value of PI to several places
      double PIVAL = 3.141592653589793238462643383;

      // All processors should already have this as it 
      // came from the command line - but just in case,
      // we broadcast it here to make sure.
      FunctionEntry("Broadcast");
      _communicator.BroadCast(ndiv,0);
      FunctionExit("Broadcast");
      
      // This block partitions the 
      // domain [0,1] with ndiv 
      // intervals among nproc processors
      int nper = ndiv/nproc;
      int nvol = nper*nproc;
      int leftover = ndiv - nvol;
      int myn = nper;
      if(myid < leftover)
        myn++;
      int mystart = 0;
      for(int i = 0; i < myid;i++){
        mystart += nper;
        if(i < leftover)
          mystart++;
      }   
      // If there are less divisions than processors, then
      // just forget about domain decomposition and do everything
      // on processor 0.
      if(nper == 0){
        if(myid == 0) myn = ndiv;
        else myn = 0;
      }
        
      // Use the results from domain decomposition to 
      // set the domain [a,b] for this processor and get the 
      // stepsize.
      double h   = 1.0/(static_cast<double>(ndiv));
      double a = h*mystart;
      double b = a + h*myn;

      // Integrate f on this processor's subdomain using trapezoid quadrature
      FunctionEntry("TrapezoidMethod");
      double my_tpi = 0.0;
      if(myn > 0){ // if there are points in this processor's domain
        try {
          FunctionEntry("TrapezoidQuadrature");
          my_tpi = GridConversion::TrapezoidQuadrature(f,a,b,myn);
          FunctionExit("TrapezoidQuadrature");
        } catch (...){
          StdOut("Numerical limits of GridConversion::TrapezoidQuadrature exceeded.");
          my_tpi = 0.0;
        }
      }
      double tpi = 0.0;
      // Sum up the contributions from each processor and store the results on
      // processor 0 in "tpi".
      FunctionEntry("Reduce"); // time the communication
      _communicator.Reduce(my_tpi, tpi,IRAD::Comm::DTDOUBLE, IRAD::Comm::SUMOP, 0);
      FunctionExit("Reduce");  // end of the communication
      FunctionExit("TrapezoidMethod");

      // Integrate f on this processor's subdomain using midpoint quadrature
      FunctionEntry("MidPointMethod");
      double my_mppi = 0.0;
      if(myn > 0) {  // if there are points in this processor's domain
        try{
          FunctionEntry("MidPointQuadrature");
          my_mppi = GridConversion::MidPointQuadrature(f,a,b,myn);
          FunctionExit("MidPointQuadrature");
        } catch (...){
          StdOut("Numerical limits of GridConversion::MidPointQuadrature exceeded.");
          my_mppi = 0.0;
        }
      }
      double mppi = 0.0;
      // Sum up the contributions from each processor and store the results on
      // processor 0 in "mppi".
      FunctionEntry("Reduce"); // time the communication
      _communicator.Reduce(my_mppi, mppi,IRAD::Comm::DTDOUBLE, IRAD::Comm::SUMOP, 0);
      FunctionExit("Reduce");  // end of the communication
      FunctionExit("MidPointMethod");
      
      // Report the results to stdout or to file if one was specified.
      FunctionEntry("IO");
      if (!myid) {
        if(use_file){
          Ouf << ndiv << " " << std::setprecision(16) << tpi << " " 
              << std::setprecision(4)  << std::fabs(tpi-PIVAL) << " "
              << std::setprecision(16) << mppi << " " 
              << std::setprecision(4)  << std::fabs(mppi-PIVAL) << " "
              << std::endl;
          Ouf.close();
        }
        else if(verblevel) {
          std::ostringstream Ostr;
          Ostr << "With " << ndiv << " divisions, PI was calculated:" << std::endl
               << "MidPointQuadrature:  "
               << std::setprecision(16) << mppi << "\t\t" 
               << std::setprecision(4) << std::fabs(mppi - PIVAL) << std::endl
               << "TrapezoidQuadrature: " 
               << std::setprecision(16) << tpi << "\t\t"
               << std::setprecision(4)  << std::fabs(tpi - PIVAL) << std::endl;
          StdOut(Ostr.str());
        }
      }
      FunctionExit("IO");
      //
      // ---------- Program End ----------------  
      
      // Update the stacker/profiler that we are exiting 
      // this function.
      FunctionExit("Run");
      // return 0 for success
      return(0);
    };