org.apache.sysml.runtime.controlprogram.parfor.stat.StatisticMonitor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of systemml Show documentation
Show all versions of systemml Show documentation
Declarative Machine Learning
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.sysml.runtime.controlprogram.parfor.stat;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map.Entry;
import org.apache.sysml.runtime.controlprogram.ParForProgramBlock.PExecMode;
import org.apache.sysml.runtime.controlprogram.ParForProgramBlock.POptMode;
import org.apache.sysml.runtime.controlprogram.ParForProgramBlock.PTaskPartitioner;
import org.apache.sysml.runtime.controlprogram.ParForProgramBlock.PDataPartitioner;
/**
* This singleton statistic monitor is used to consolidate all parfor runtime statistics.
* Its purpose is mainly for (1) debugging and (2) potential optimization.
*
*
*
*/
public class StatisticMonitor
{
private static HashMap _mapPwPf; //mapping parfor to parworkers
private static HashMap>> _pfstats; //parfor statistics
private static HashMap>> _pwstats; //parworker statistics
private static boolean _disabled;
static
{
_mapPwPf = new HashMap();
_pfstats = new HashMap>>();
_pwstats = new HashMap>>();
}
/**
* Register information about parent-child relationships of parworkers and
* parfor program blocks, with a parfor can be related to one or many parworkers.
*
* @param pfid
* @param pwid
*/
public static void putPfPwMapping( long pfid, long pwid )
{
if( _disabled )
return; // do nothing
_mapPwPf.put(pwid, pfid);
}
/**
* Puts a specific parfor statistic for future analysis into the repository.
*
* @param id
* @param type
* @param s
*/
public static void putPFStat( long id, Stat type, double s)
{
if( _disabled )
return; // do nothing
//check if parfor exists
if( !_pfstats.containsKey(id) )
_pfstats.put(id, new HashMap>());
HashMap> allstats = _pfstats.get(id);
//check if stat type exists
if( !allstats.containsKey(type) )
allstats.put(type, new LinkedList());
LinkedList stats = allstats.get(type);
//add new stat
stats.addLast(s);
}
/**
* Puts a specific parworker statistic for future analysis into the repository.
*
* @param id
* @param type
* @param s
*/
public static void putPWStat( long id, Stat type, double s)
{
if( _disabled )
return; // do nothing
//check if parworker exists
if( !_pwstats.containsKey(id) )
_pwstats.put(id, new HashMap>());
HashMap> allstats = _pwstats.get(id);
//check if stat type exists
if( !allstats.containsKey(type) )
allstats.put(type, new LinkedList());
LinkedList stats = allstats.get(type);
//add new stat
stats.addLast(s);
}
/**
* Cleans up the whole repository by discarding all collected information.
*/
public static void cleanUp()
{
_mapPwPf.clear();
_pfstats.clear();
_pwstats.clear();
}
/**
* Globally disables statistic monitor for the currently activ JVM.
*/
public static void disableStatMonitoring()
{
_disabled = true;
}
/**
* Creates a nested statistic report of all parfor and parworker instances.
* This should be called after completed execution.
*
* NOTE: This report is mainly for analysis and debugging purposes.
*
* @return
*/
public static String createReport()
{
StringBuilder sb = new StringBuilder();
sb.append("############################################## \n");
sb.append("## ParFOR Runtime Statistics Report ## \n");
sb.append("############################################## \n");
//foreach parfor
for( Long pfid : _pfstats.keySet() )
{
sb.append("\n");
sb.append("##############################################\n");
sb.append("## ParFOR (ID="+ pfid +") Execution Statistics:\n");
HashMap> stats = _pfstats.get(pfid);
//foreach parfor execute
for( int i=0; i e : _mapPwPf.entrySet() )
{
if( e.getValue().equals(pfid) )
{
long pid = e.getKey();
HashMap> stats2 = _pwstats.get(pid);
if(stats2==null)
continue;
int ntasks=(int)(double)stats2.get(Stat.PARWRK_NUMTASKS).get(0);
int niters=(int)(double)stats2.get(Stat.PARWRK_NUMITERS).get(0);
sb.append(" ------------------------\n");
sb.append(" --- ParWorker #"+count2+" (ID="+ pid +") Execution Statistics:\n");
sb.append(" Num Tasks = "+ntasks+"\n");
sb.append(" Num Iters = "+niters+"\n");
sb.append(" Time EXEC = "+stats2.get(Stat.PARWRK_EXEC_T).get(0)+"ms\n");
LinkedList taskexec = stats2.get(Stat.PARWRK_TASK_T);
LinkedList tasksize = stats2.get(Stat.PARWRK_TASKSIZE);
LinkedList iterexec = stats2.get(Stat.PARWRK_ITER_T);
int count3=0;
for( int k1=0; k1