All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.electric.tool.util.concurrent.Parallel Maven / Gradle / Ivy

/* -*- tab-width: 4 -*-
 *
 * Electric(tm) VLSI Design System
 *
 * File: Parallel.java
 *
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
 *
 * Electric(tm) is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * Electric(tm) is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Electric(tm); see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, Mass 02111-1307, USA.
 */
package com.sun.electric.tool.util.concurrent;

import com.sun.electric.tool.util.concurrent.datastructures.IStructure;
import com.sun.electric.tool.util.concurrent.patterns.PForJob;
import com.sun.electric.tool.util.concurrent.patterns.PForTask;
import com.sun.electric.tool.util.concurrent.patterns.PJob;
import com.sun.electric.tool.util.concurrent.patterns.PReduceJob;
import com.sun.electric.tool.util.concurrent.patterns.PReduceJob.PReduceTask;
import com.sun.electric.tool.util.concurrent.patterns.PWhileJob;
import com.sun.electric.tool.util.concurrent.patterns.PWhileJob.PWhileTask;
import com.sun.electric.tool.util.concurrent.runtime.taskParallel.IThreadPool;
import com.sun.electric.tool.util.concurrent.utils.BlockedRange;

/**
 * This class simplifies the interface for the parallel base patterns
 * 
 * @author Felix Schmidt
 */
public class Parallel {
    
    public static > void For(T range, PForTask task, IThreadPool pool) {
        (new PForJob(range, task, pool)).execute(); 
    }

	/**
	 * Parallel For Loop (1- and 2-dimensional)
	 * 
	 * @param range
	 *            1- or 2-dimensional
	 * @param task
	 *            task object (body of for loop)
	 */
	public static > void For(T range, PForTask task) {
		(new PForJob(range, task)).execute();
	}

	/**
	 * Parallel reduce. Reduce is a parallel for loop with a result aggregation
	 * at the end of processing.
	 * 
	 * @param 
	 *            return type (implicit)
	 * @param range
	 *            1- or 2-dimensional
	 * @param task
	 *            body of reduce loop
	 * @return aggregated result
	 */
	public static > T Reduce(K range, PReduceTask task) {
		PReduceJob pReduceJob = new PReduceJob(range, task);
		pReduceJob.execute();

		return pReduceJob.getResult();
	}

	/**
	 * Parallel while loop: iterates while elements in the data structure
	 * 
	 * @param 
	 *            return type (implicit)
	 * @param data
	 *            data structure for work
	 * @param task
	 *            while loop body
	 */
	public static  void While(IStructure data, PWhileTask task) {
		PJob pWhileJob = new PWhileJob(data, task);
		pWhileJob.execute();
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy