text:
static char help[] = "Solves a linear system with various combinations of KSP + PC.\n\
  -f <input_file> : petsc binary file containing matrix\n\n";

#include <petscksp.h>
#include <petsctime.h>

extern PetscErrorCode MyKSPMonitor(KSP,PetscInt,PetscReal,void*);
extern PetscErrorCode Solve(KSPType,PCType,PetscInt,PetscBool,Mat);

PetscLogDouble lowestTime = 9.0e+99, startTime = 0;
PetscReal lowestNorm = 9.0e+99, pNorm;

PetscInt matRows = 0;
PetscBool hasConverged = PETSC_FALSE;

#undef __FUNCT__
#define __FUNCT__ "main"
int main(int argc,char **args)
{
  Vec            d;      /* vector for fixing missing diagonal entries */
  Mat            A;       /* linear system matrix */

  PetscErrorCode ierr;
  PetscMPIInt    size;
  PetscBool      flg, pcSideLeft=PETSC_TRUE,isSymmetric=PETSC_FALSE;

  char           filein[PETSC_MAX_PATH_LEN],buf[PETSC_MAX_PATH_LEN],link[PETSC_MAX_PATH_LEN];
  char*          lnk;
  FILE*          file;
  PetscInt       k,m,n,nnz,col,row;
  PetscScalar    val;

  // Initialize Petsc
  PetscInitialize(&argc,&args,(char *)0,help);
  ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr);
  if (size != 1) SETERRQ(PETSC_COMM_WORLD,1,"This is a uniprocessor program only!");

  ierr = PetscOptionsGetString(PETSC_NULL,"-f",filein,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr);
  if (!flg) {
    SETERRQ(PETSC_COMM_WORLD,1,"Must indicate matrix file with the -f option");
  }

  // Open Matrix Market File for reading
  ierr = PetscFOpen(PETSC_COMM_SELF,filein,"r",&file);CHKERRQ(ierr);

  // Check if matrix is symmetric
  do {
    fgets(buf,PETSC_MAX_PATH_LEN-1,file);
    if(strstr(buf, "symmetric") != NULL){
      isSymmetric = PETSC_TRUE;
    }
    if(strstr(buf, "http")){
      strcpy(link,buf);
      lnk = link;
    }
  }while (buf[0] == '%');

  // Get matrix size
  sscanf(buf,"%d %d %d\n",&m,&n,&nnz);
  // Set global variable for row
  matRows = m;

  // Create vector d for fixing missing diagonal entries
  ierr = VecCreate(PETSC_COMM_WORLD,&d);CHKERRQ(ierr);
  ierr = VecSetSizes(d,PETSC_DECIDE,n);CHKERRQ(ierr);
  ierr = VecSetFromOptions(d);CHKERRQ(ierr);

  // Set all entries to 0
  ierr = VecSet(d,0);CHKERRQ(ierr);

  // Set matrix format
  ierr = MatCreateSeqAIJ(PETSC_COMM_WORLD,m,n,nnz*2/m,0,&A);CHKERRQ(ierr);
  ierr = MatSetOption(A,MAT_NEW_NONZERO_ALLOCATION_ERR,PETSC_FALSE);CHKERRQ(ierr);

  // Read matrix market file and build petsc matrix
  for (k=0; k<nnz; k++) {
    fscanf(file,"%d %d %le\n",&row,&col,(double*)&val);
    row = row-1; col = col-1 ;
    ierr = MatSetValues(A,1,&row,1,&col,&val,INSERT_VALUES);CHKERRQ(ierr);
    // If matrix is symmetric,
    // insert same entry on the other side of the diagonal
    if(isSymmetric){
      if (row != col){
        ierr = MatSetValues(A,1,&col,1,&row,&val,INSERT_VALUES);CHKERRQ(ierr);
      }
    }
    // Matrix has diagonal entry,
    // set that entry of vector d to 1
    if(row == col)
       VecSetValue(d,row,1,ADD_VALUES);
  }

  VecAssemblyBegin(d); VecAssemblyEnd(d);
  PetscScalar dv[1];
  val = 0;
  for(k=0; k<m; k++){
    VecGetValues(d,1,&k,dv);
    // If an entry in vector d is zero,
    // matrix A is missing that diagonal entry.
    if(dv[0] == 0) // Insert a 0 at that location of A
      ierr = MatSetValues(A,1,&k,1,&k,&val,INSERT_VALUES);CHKERRQ(ierr);
  }

  fclose(file);

  // Finish builing matrix
  ierr = MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
  ierr = MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);

  // Print link to the matrix
  PetscPrintf(PETSC_COMM_WORLD,"%s",lnk);

  // Solve the linear system with the following KSP+PC combinations

  if(isSymmetric){ // If matrix is symmetric, try this order

    // Apply preconditioner from left
    pcSideLeft = PETSC_TRUE;

    Solve(KSPCG,PCILU,0,pcSideLeft,A);
    Solve(KSPCG,PCILU,1,pcSideLeft,A);
    Solve(KSPCG,PCILU,2,pcSideLeft,A);
    Solve(KSPCG,PCJACOBI,-1,pcSideLeft,A);
    Solve(KSPCG,PCSOR,-1,pcSideLeft,A);
    Solve(KSPCG,PCNONE,-1,pcSideLeft,A);

    Solve(KSPCGS,PCILU,0,pcSideLeft,A);
    Solve(KSPCGS,PCILU,1,pcSideLeft,A);
    Solve(KSPCGS,PCILU,2,pcSideLeft,A);
    Solve(KSPCGS,PCJACOBI,-1,pcSideLeft,A);
    Solve(KSPCGS,PCSOR,-1,pcSideLeft,A);
    Solve(KSPCGS,PCNONE,-1,pcSideLeft,A);

    Solve(KSPTFQMR,PCILU,0,pcSideLeft,A);
    Solve(KSPTFQMR,PCILU,1,pcSideLeft,A);
    Solve(KSPTFQMR,PCILU,2,pcSideLeft,A);
    Solve(KSPTFQMR,PCJACOBI,-1,pcSideLeft,A);
    Solve(KSPTFQMR,PCSOR,-1,pcSideLeft,A);
    Solve(KSPTFQMR,PCNONE,-1,pcSideLeft,A);

    Solve(KSPBICG,PCILU,0,pcSideLeft,A);
    Solve(KSPBICG,PCILU,1,pcSideLeft,A);
    Solve(KSPBICG,PCILU,2,pcSideLeft,A);
    Solve(KSPBICG,PCJACOBI,-1,pcSideLeft,A);
    Solve(KSPBICG,PCNONE,-1,pcSideLeft,A);

    Solve(KSPBCGS,PCILU,0,pcSideLeft,A);
    Solve(KSPBCGS,PCILU,1,pcSideLeft,A);
    Solve(KSPBCGS,PCILU,2,pcSideLeft,A);
    Solve(KSPBCGS,PCJACOBI,-1,pcSideLeft,A);
    Solve(KSPBCGS,PCSOR,-1,pcSideLeft,A);
    Solve(KSPBCGS,PCNONE,-1,pcSideLeft,A);

    Solve(KSPGMRES,PCILU,0,pcSideLeft,A);
    Solve(KSPGMRES,PCILU,1,pcSideLeft,A);
    Solve(KSPGMRES,PCILU,2,pcSideLeft,A);
    Solve(KSPGMRES,PCJACOBI,-1,pcSideLeft,A);
    Solve(KSPGMRES,PCSOR,-1,pcSideLeft,A);
    Solve(KSPGMRES,PCNONE,-1,pcSideLeft,A);

    // FGMRES supports preconditioning from right side only
    // So set pcSideLeft to false
    pcSideLeft = PETSC_FALSE;

    Solve(KSPFGMRES,PCILU,0,pcSideLeft,A);
    Solve(KSPFGMRES,PCILU,1,pcSideLeft,A);
    Solve(KSPFGMRES,PCILU,2,pcSideLeft,A);
    Solve(KSPFGMRES,PCJACOBI,-1,pcSideLeft,A);
    Solve(KSPFGMRES,PCSOR,-1,pcSideLeft,A);
    Solve(KSPFGMRES,PCNONE,-1,pcSideLeft,A);

  }else{ // If matrix is unsymmetric, try this order

    pcSideLeft = PETSC_TRUE;

    Solve(KSPBCGS,PCILU,0,pcSideLeft,A);
    Solve(KSPBCGS,PCILU,1,pcSideLeft,A);
    Solve(KSPBCGS,PCILU,2,pcSideLeft,A);
    Solve(KSPBCGS,PCJACOBI,-1,pcSideLeft,A);
    Solve(KSPBCGS,PCSOR,-1,pcSideLeft,A);
    Solve(KSPBCGS,PCNONE,-1,pcSideLeft,A);

    Solve(KSPGMRES,PCILU,0,pcSideLeft,A);
    Solve(KSPGMRES,PCILU,1,pcSideLeft,A);
    Solve(KSPGMRES,PCILU,2,pcSideLeft,A);
    Solve(KSPGMRES,PCJACOBI,-1,pcSideLeft,A);
    Solve(KSPGMRES,PCSOR,-1,pcSideLeft,A);
    Solve(KSPGMRES,PCNONE,-1,pcSideLeft,A);

    // FGMRES supports preconditioning from right side only
    // So set pcSideLeft to false
    pcSideLeft = PETSC_FALSE;

    Solve(KSPFGMRES,PCILU,0,pcSideLeft,A);
    Solve(KSPFGMRES,PCILU,1,pcSideLeft,A);
    Solve(KSPFGMRES,PCILU,2,pcSideLeft,A);
    Solve(KSPFGMRES,PCJACOBI,-1,pcSideLeft,A);
    Solve(KSPFGMRES,PCSOR,-1,pcSideLeft,A);
    Solve(KSPFGMRES,PCNONE,-1,pcSideLeft,A);

    pcSideLeft = PETSC_TRUE;

    Solve(KSPBICG,PCILU,0,pcSideLeft,A);
    Solve(KSPBICG,PCILU,1,pcSideLeft,A);
    Solve(KSPBICG,PCILU,2,pcSideLeft,A);
    Solve(KSPBICG,PCJACOBI,-1,pcSideLeft,A);
    Solve(KSPBICG,PCNONE,-1,pcSideLeft,A);

    Solve(KSPTFQMR,PCILU,0,pcSideLeft,A);
    Solve(KSPTFQMR,PCILU,1,pcSideLeft,A);
    Solve(KSPTFQMR,PCILU,2,pcSideLeft,A);
    Solve(KSPTFQMR,PCJACOBI,-1,pcSideLeft,A);
    Solve(KSPTFQMR,PCSOR,-1,pcSideLeft,A);
    Solve(KSPTFQMR,PCNONE,-1,pcSideLeft,A);

    Solve(KSPCGS,PCILU,0,pcSideLeft,A);
    Solve(KSPCGS,PCILU,1,pcSideLeft,A);
    Solve(KSPCGS,PCILU,2,pcSideLeft,A);
    Solve(KSPCGS,PCJACOBI,-1,pcSideLeft,A);
    Solve(KSPCGS,PCSOR,-1,pcSideLeft,A);
    Solve(KSPCGS,PCNONE,-1,pcSideLeft,A);

    Solve(KSPCG,PCILU,0,pcSideLeft,A);
    Solve(KSPCG,PCILU,1,pcSideLeft,A);
    Solve(KSPCG,PCILU,2,pcSideLeft,A);
    Solve(KSPCG,PCJACOBI,-1,pcSideLeft,A);
    Solve(KSPCG,PCSOR,-1,pcSideLeft,A);
    Solve(KSPCG,PCNONE,-1,pcSideLeft,A);
  }
  //PetscPrintf(PETSC_COMM_WORLD,"L time: %e | L norm: %G \n",lowestTime,lowestNorm);

  // Destroy Matrix and Vector
  ierr = VecDestroy(&d);CHKERRQ(ierr);
  ierr = MatDestroy(&A);CHKERRQ(ierr);
  ierr = PetscFinalize();
  return 0;
}

PetscErrorCode Solve(KSPType kt, PCType pt, PetscInt pcFactorLevel, PetscBool pcSideLeft, Mat A){

  PetscLogDouble solveTime,endTime;
  PetscInt       its;
  PetscReal      norm;
  PetscErrorCode ierr;
  KSP            ksp; // Linear solver context
  PC             pc; // Preconditioner
  Vec            b,x,u; // RHS, solution, vector for norm calculation

  // Create RHS vector
  ierr = VecCreate(PETSC_COMM_WORLD,&b);CHKERRQ(ierr);
  ierr = VecSetSizes(b,PETSC_DECIDE,matRows);CHKERRQ(ierr);
  ierr = VecSetFromOptions(b);CHKERRQ(ierr);
  ierr = VecSet(b,1);CHKERRQ(ierr);

  // Create vectors x and u
  ierr = VecDuplicate(b,&x);CHKERRQ(ierr);
  ierr = VecDuplicate(b,&u);CHKERRQ(ierr);

  // Create KSP
  ierr = KSPCreate(PETSC_COMM_WORLD,&ksp); CHKERRQ(ierr);
  ierr = KSPSetFromOptions(ksp); CHKERRQ(ierr);
  // Setup KSP monitor
  ierr = KSPMonitorSet(ksp,MyKSPMonitor,NULL,0); CHKERRQ(ierr);

  ierr = KSPSetOperators(ksp,A,A);CHKERRQ(ierr);
  ierr = KSPSetInitialGuessNonzero(ksp,PETSC_FALSE);CHKERRQ(ierr);
  // Set KSP type
  ierr = KSPSetType(ksp,kt);CHKERRQ(ierr);
  // Set which side PC will be applied from
  if(pcSideLeft == PETSC_FALSE){
    ierr = KSPSetPCSide(ksp,PC_RIGHT);CHKERRQ(ierr);
  }
  ierr = KSPGetPC(ksp,&pc);CHKERRQ(ierr);
  // Set PC type
  ierr = PCSetType(pc,pt);CHKERRQ(ierr);
  if(pcFactorLevel != -1){
    ierr = PCFactorSetLevels(pc,pcFactorLevel);CHKERRQ(ierr);
  }
  // Setup KSP
  ierr = KSPSetUp(ksp);CHKERRQ(ierr);

  ierr = PetscTime(&startTime);CHKERRQ(ierr);
  // Make sure the program doesn't crash
  PetscPushErrorHandler(PetscIgnoreErrorHandler,NULL);
  ierr = KSPSolve(ksp,b,x);
  PetscPopErrorHandler();
  // Check if anything went wrong
  if(ierr == 0 || ierr == -1){
    // If no error occurred or stopped by MyKSPMonitor, compute normal and stuff
    ierr = KSPGetIterationNumber(ksp,&its);CHKERRQ(ierr);
    ierr = MatMult(A,x,u);CHKERRQ(ierr);
    ierr = VecAXPY(u,-1.0,b);CHKERRQ(ierr);
    ierr = VecNorm(u,NORM_2,&norm);CHKERRQ(ierr);
    ierr = PetscTime(&endTime);CHKERRQ(ierr);
    // Compute solve time
    solveTime = endTime - startTime;
    // Check if KSP converged
    KSPConvergedReason reason;
    KSPGetConvergedReason(ksp,&reason);
    if(reason > 0){
      hasConverged = PETSC_TRUE;
      if(solveTime < lowestTime){
        lowestTime = solveTime;
      }
      if(pNorm < lowestNorm){
        lowestNorm = pNorm;
      }
    }
    // Print method info
    if(pcFactorLevel != -1){
      ierr = PetscPrintf(PETSC_COMM_WORLD,"%s | %s(%D)",kt,pt,pcFactorLevel);CHKERRQ(ierr);
    }
    else{
      ierr = PetscPrintf(PETSC_COMM_WORLD,"%s | %s",kt,pt);CHKERRQ(ierr);
    }
    // Print convergence code, solve time, preconditioned norm, iterations
    ierr = PetscPrintf(PETSC_COMM_WORLD," | %D | %e | %G | %D\n",reason,solveTime,pNorm,its);CHKERRQ(ierr);

  }
  else{ // Disaster happened, print error code
    if(pcFactorLevel != -1){
      ierr = PetscPrintf(PETSC_COMM_WORLD,"%s | %s(%D) | Failed | Errorcode %D ||\n",kt,pt,pcFactorLevel,ierr);CHKERRQ(ierr);
    }else{
      ierr = PetscPrintf(PETSC_COMM_WORLD,"%s | %s | Failed | Errorcode %D ||\n",kt,pt,ierr);CHKERRQ(ierr);
    }
  }

  // Destroy KSP and vector
  ierr = KSPDestroy(&ksp);CHKERRQ(ierr);
  ierr = VecDestroy(&x);CHKERRQ(ierr);
  ierr = VecDestroy(&b);CHKERRQ(ierr);
  ierr = VecDestroy(&u);CHKERRQ(ierr);
  return 0;
}

PetscErrorCode MyKSPMonitor(KSP ksp,PetscInt n,PetscReal rnorm,void *dummy)
{
  PetscLogDouble currentTime = 0;
  PetscTime(&currentTime);
  //PetscPrintf(PETSC_COMM_WORLD,"It: %D, norm: %G\n",n,rnorm);
  pNorm = rnorm;
  if(hasConverged){
    if(currentTime - startTime > (lowestTime*10)){
      if(rnorm > lowestNorm){
        SETERRQ(PETSC_COMM_WORLD,-1,"This is taking way too long!\n");
      }
    }
  }
  return 0;
}


text:
<?php

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');

if(!class_exists('VmModel'))require(VMPATH_ADMIN.DS.'helpers'.DS.'vmmodel.php');

/**
 * Model class for VirtueMart Manufacturers
 *
 * @package VirtueMart
 * @subpackage Manufacturer
 * @author Max Milbers
 * @todo Replace getOrderUp and getOrderDown with JTable move function. This requires the virtuemart_product_category_xref table to replace the ordering with the ordering column
 */
class VirtueMartModelManufacturer extends VmModel {

	/**
	 * constructs a VmModel
	 * setMainTable defines the maintable of the model
	 * @author Max Milbers
	 */
	function __construct() {
		parent::__construct('virtuemart_manufacturer_id');
		$this->setMainTable('manufacturers');
		$this->addvalidOrderingFieldName(array('m.virtuemart_manufacturer_id','mf_name','mf_desc','mf_category_name','mf_url'));
		$this->removevalidOrderingFieldName('virtuemart_manufacturer_id');
		$this->_selectedOrdering = 'mf_name';
		$this->_selectedOrderingDir = 'ASC';
	}

	/**
	* Load a single manufacturer
	*/
	public function getManufacturer($id = 0) {

		if(!empty($id)) $this->_id = (int)$id;

		if(empty($this->_cache[$this->_id])){
			$this->_cache[$this->_id] = $this->getTable('manufacturers');
			$this->_cache[$this->_id]->load($this->_id);

			$xrefTable = $this->getTable('manufacturer_medias');
			$this->_cache[$this->_id]->virtuemart_media_id = $xrefTable->load($this->_id);
		}

		return $this->_cache[$this->_id];
	}

     /**
	 * Bind the post data to the manufacturer table and save it
     *
     * @author Max Milbers
     * @return boolean True is the save was successful, false otherwise.
	 */
	public function store(&$data) {

		// Setup some place holders
		$table = $this->getTable('manufacturers');

		$table->bindChecknStore($data);
		$errors = $table->getErrors();
		foreach($errors as $error){
			vmError($error);
		}

		// Process the images
		$mediaModel = VmModel::getModel('Media');
		$mediaModel->storeMedia($data,'manufacturer');
		$errors = $mediaModel->getErrors();
		foreach($errors as $error){
			vmError($error);
		}
		$cache = JFactory::getCache('com_virtuemart_cat_manus','callback');
		$cache->clean();
		return $table->virtuemart_manufacturer_id;
	}

    /**
     * Returns a dropdown menu with manufacturers
     * @author Max Milbers
	 * @return object List of manufacturer to build filter select box
	 */
	function getManufacturerDropdown() {
		$db = JFactory::getDBO();
		$query = "SELECT `virtuemart_manufacturer_id` AS `value`, `mf_name` AS text, '' AS disable
						FROM `#__virtuemart_manufacturers_".VmConfig::$vmlang."` ORDER BY `mf_name` ASC";
		$db->setQuery($query);
		$options = $db->loadObjectList();
		array_unshift($options, JHtml::_('select.option',  '0', '- '. vmText::_('COM_VIRTUEMART_SELECT_MANUFACTURER') .' -' ));
		return $options;
	}

    /**
	 * Retireve a list of countries from the database.
	 *
     * @param string $onlyPuiblished True to only retreive the publish countries, false otherwise
     * @param string $noLimit True if no record count limit is used, false otherwise
	 * @return object List of manufacturer objects
	 */
	public function getManufacturers($onlyPublished=false, $noLimit=false, $getMedia=false) {

		$this->_noLimit = $noLimit;
		$mainframe = JFactory::getApplication();
		$option	= 'com_virtuemart';

		$virtuemart_manufacturercategories_id	= $mainframe->getUserStateFromRequest( $option.'virtuemart_manufacturercategories_id', 'virtuemart_manufacturercategories_id', 0, 'int' );
		$search = $mainframe->getUserStateFromRequest( $option.'search', 'search', '', 'string' );

		static $_manufacturers = array();

		$hash = $search.serialize($virtuemart_manufacturercategories_id).VmConfig::$vmlang.(int)$onlyPublished.(int)$this->_noLimit.(int)$getMedia;

		if (array_key_exists ($hash, $_manufacturers)) {
			vmdebug('Return cached getManufacturers');
			return $_manufacturers[$hash];
		}

		$where = array();
		if ($virtuemart_manufacturercategories_id > 0) {
			$where[] .= ' `m`.`virtuemart_manufacturercategories_id` = '. $virtuemart_manufacturercategories_id;
		}

		$joinedTables = ' FROM `#__virtuemart_manufacturers` as m';
		$select = ' `m`.*';
		if ( $search && $search != 'true') {
			$db = JFactory::getDBO();
			$search = '"%' . $db->escape( $search, true ) . '%"' ;
			//$search = $db->Quote($search, false);
			$where[] .= ' LOWER( `mf_name` ) LIKE '.$search;
		}

		$ordering = $this->_getOrdering();
		//if ( $search && $search != 'true' or strpos($ordering,'mf_')!==FALSE or $ordering == 'm.virtuemart_manufacturer_id' ) {
			$select .= ',`#__virtuemart_manufacturers_'.VmConfig::$vmlang.'`.*, mc.`mf_category_name` ';
			$joinedTables .= ' INNER JOIN `#__virtuemart_manufacturers_'.VmConfig::$vmlang.'` USING (`virtuemart_manufacturer_id`) ';
			$joinedTables .= ' LEFT JOIN `#__virtuemart_manufacturercategories_'.VmConfig::$vmlang.'` AS mc on  mc.`virtuemart_manufacturercategories_id`= `m`.`virtuemart_manufacturercategories_id` ';
		//}

		if ($onlyPublished) {
			$where[] .= ' `m`.`published` = 1';
		}

		$groupBy=' ';
		if($getMedia){
			$select .= ',mmex.virtuemart_media_id ';
			$joinedTables .= 'LEFT JOIN `#__virtuemart_manufacturer_medias` as mmex ON `m`.`virtuemart_manufacturer_id`= mmex.`virtuemart_manufacturer_id` ';
			$groupBy=' GROUP BY `m`.`virtuemart_manufacturer_id` ';

		}
		$whereString = ' ';
		if (count($where) > 0) $whereString = ' WHERE '.implode(' AND ', $where).' ' ;

		$_manufacturers[$hash] = $this->_data = $this->exeSortSearchListQuery(0,$select,$joinedTables,$whereString,$groupBy,$ordering );

		return $_manufacturers[$hash];
	}

	static function getManufacturersOfProductsInCategory($virtuemart_category_id,$vmlang,$mlang = false){

		if($mlang){
			$query = 'SELECT DISTINCT IFNULL(l.`mf_name`,ld.mf_name) as mf_name,IFNULL(l.`virtuemart_manufacturer_id`,ld.`virtuemart_manufacturer_id`) as virtuemart_manufacturer_id
FROM `#__virtuemart_manufacturers_'.VmConfig::$defaultLang.'` as ld
LEFT JOIN `#__virtuemart_manufacturers_'.$vmlang.'` as l using (`virtuemart_manufacturer_id`)';
			vmdebug('getManufacturersOfProductsInCategory use language fallback');
		} else {
			$query = 'SELECT DISTINCT l.`mf_name`,l.`virtuemart_manufacturer_id` FROM `#__virtuemart_manufacturers_' . $vmlang . '` as l';
		}
		// if ($mf_virtuemart_product_ids) {

		$query .= ' INNER JOIN `#__virtuemart_product_manufacturers` AS pm using (`virtuemart_manufacturer_id`)';
		$query .= ' INNER JOIN `#__virtuemart_products` as p ON p.`virtuemart_product_id` = pm.`virtuemart_product_id` ';
		if ($virtuemart_category_id) {
			$query .= ' INNER JOIN `#__virtuemart_product_categories` as c ON c.`virtuemart_product_id` = pm.`virtuemart_product_id` ';
		}
		$query .= ' WHERE p.`published` =1';
		if ($virtuemart_category_id) {
			$query .= ' AND c.`virtuemart_category_id` =' . (int)$virtuemart_category_id;
		}
		$query .= ' ORDER BY `mf_name`';
		$db = JFactory::getDBO();
		$db->setQuery ($query);
		return $db->loadObjectList ();
	}
}
// pure php no closing tag

redpajama_set_name: RedPajamaGithub


text:
var async = require('async');
var migrate = require('./archivist-migrate');

exports.setup = function (mage, options, cb) {
	async.series([
		(callback) => mage.core.loggingService.setup(callback),
		(callback) => mage.core.archivist.setup(callback)
	], cb);
};

exports.start = function (mage, options, cb) {
	var vaults = mage.core.archivist.getPersistentVaults();
	var vaultNames = options.vaults ? options.vaults.split(',') : Object.keys(vaults);

	async.eachSeries(vaultNames, function (vaultName, callback) {
		var vault = vaults[vaultName];

		if (!vault) {
			mage.core.logger.warning('Vault not configured:', vaultName);
			return callback();
		}

		var preventCreate = mage.core.config.get(['archivist', 'vaults', vaultName, 'config', 'preventCreate'], false);
		if (preventCreate) {
			mage.core.logger.notice('Vault', vault.name, 'has disabled create operation. Skipping.');
			return callback();
		}

		if (typeof vault.createDatabase === 'function') {
			vault.createDatabase(callback);
		} else {
			mage.core.logger.notice('Vault', vault.name, 'has no create operation. Skipping.');
			callback();
		}
	}, function (error) {
		if (error) {
			mage.core.logger.emergency(error);
			return cb(error);
		}

		mage.core.archivist.openVaults(function (error) {
			if (error) {
				mage.core.logger.emergency(error);
				return cb(error);
			}

			migrate.start(mage, options, cb);
		});
	});
};

exports.shutdown = function (mage, options, cb) {
	mage.core.archivist.closeVaults();
	mage.core.loggingService.destroy(cb);
};


text:
from __future__ import absolute_import

from . import apps, servers, configapps

__version__ = "0.1.3"

__all__ = ['apps', 'servers', 'configapps']


text:
namespace CassandraDiff {

/// Field Information enough to know what/why there is a difference
/// Between DB value and Request value
class FieldInfo
{
public:
    FieldInfo(const std::string & name, const std::string & key, const std::string & dbvalue, const std::string & reqvalue) :
        mName(name),
        mMultivalueKey(key),
        mDBValue(dbvalue),
        mReqValue(reqvalue) {};

public:
    /// Field name in the db
    std::string mName;
    /// Multivalue/Collection index/key
    std::string mMultivalueKey;
    /// Value retrieved in Database
    std::string mDBValue;
    /// Value about to be set from Request
    std::string mReqValue;
};

std::ostream& operator<<(std::ostream & strm,const FieldInfo& f);

/// MultiMap of UNIQUE_ID to RequestInfo
/// There can be more than one request per UNIQUE_ID, with N fields per requests
class Differences: public std::multimap<std::string, FieldInfo>
{
public:
    boost::mutex & getMutex() { return mMutex;};
private:
    boost::mutex mMutex;
};

}


text:
/**
 * This is a factory definition for a gist file
 */
import Mirage/*, {faker} */ from 'ember-cli-mirage';

export default Mirage.Factory.extend({
  type() {
    let extension = this.filename.substring(this.filename.lastIndexOf("."), this.filename.length);
    switch (extension) {
      case ".hbs":
        return "text/plain";
      case ".css":
        return "text/css";
      case ".js":
        return "application/javascript";
      case ".json":
        return "application/json";
    }
  },
  language() {
    let extension = this.filename.substring(this.filename.lastIndexOf("."), this.filename.length);
    switch (extension) {
      case ".hbs":
        return "Handlebars";
      case ".css":
        return "CSS";
      case ".js":
        return "JavaScript";
      case ".json":
        return "JSON";
    }
  },
  raw_url() {
    return `https://gist.githubusercontent.com/${this.login}/${this.gist_id}/raw/${this.commit}/${this.filename}`;
  },
  size() {
    return this.content.length;
  },
  truncated: false
});

/* Sample

"about.template.hbs": {
  "filename": "about.template.hbs",
  "type": "text/plain",
  "language": "Handlebars",
  "raw_url": "https://gist.githubusercontent.com/Gaurav0/35de43cb81fc35ddffb2/raw/b7332edd46bd97973c1dfebf495908b8abb9b301/about.template.hbs",
  "size": 17,
  "truncated": false,
  "content": "
About Page
"
},
 */


text:
from typing import Tuple

import gdsfactory as gf
from gdsfactory.cell import cell
from gdsfactory.component import Component
from gdsfactory.components.straight import straight

@cell
def array(
    component: gf.types.ComponentSpec = straight,
    spacing: Tuple[float, float] = (150.0, 150.0),
    columns: int = 6,
    rows: int = 1,
    add_ports: bool = True,
) -> Component:
    """Returns an array of components.

    Args:
        component: to replicate.
        spacing: x, y spacing.
        columns: in x.
        rows: in y.
        add_ports: add ports from component into the array.

    Raises:
        ValueError: If columns > 1 and spacing[0] = 0.
        ValueError: If rows > 1 and spacing[1] = 0.

    .. code::

        2 rows x 4 columns
         ___        ___       ___          ___
        |   |      |   |     |   |        |   |
        |___|      |___|     |___|        |___|

         ___        ___       ___          ___
        |   |      |   |     |   |        |   |
        |___|      |___|     |___|        |___|
    """
    if rows > 1 and spacing[1] == 0:
        raise ValueError(f"rows = {rows} > 1 require spacing[1] > 0")

    if columns > 1 and spacing[0] == 0:
        raise ValueError(f"columns = {columns} > 1 require spacing[0] > 0")

    c = Component()
    component = gf.get_component(component)
    c.add_array(component, columns=columns, rows=rows, spacing=spacing)

    if add_ports and component.ports:
        for col in range(columns):
            for row in range(rows):
                for port in component.ports.values():
                    name = f"{port.name}_{row+1}_{col+1}"
                    c.add_port(name, port=port)
                    c.ports[name].move((col * spacing[0], row * spacing[1]))
    return c

if __name__ == "__main__":
    from gdsfactory.components.pad import pad

    # c2 = array(rows=2, columns=2, spacing=(100, 100))
    c2 = array(pad, rows=2, spacing=(200, 200), columns=1)

    # c3 = c2.copy()

    # nports = len(c2.get_ports_list(orientation=0))
    # assert nports == 2, nports
    # c2.show(show_ports=True)
    # c2.show(show_subports=True)
    c2.show(show_ports=True)