Files
MPIonCell/documentation/developer/html/d3/df5/moc__wtime__spu_8c-source.html
2017-10-26 19:57:24 +02:00

83 lines
6.5 KiB
HTML
Executable File

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>MPI On Cell (Documentation): src/spu/system/moc_wtime_spu.c Source File</title>
<link href="../../doxygen.css" rel="stylesheet" type="text/css">
<link href="../../tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="../../main.html"><span>Main&nbsp;Page</span></a></li>
<li><a href="../../modules.html"><span>Modules</span></a></li>
<li><a href="../../annotated.html"><span>Data&nbsp;Structures</span></a></li>
<li class="current"><a href="../../files.html"><span>Files</span></a></li>
</ul>
</div>
<h1>src/spu/system/moc_wtime_spu.c</h1><a href="../../d0/dfc/moc__wtime__spu_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001
<a name="l00002"></a>00002 <span class="preprocessor">#include &lt;<a class="code" href="../../d0/d3a/spu_2moc_8h.html">moc.h</a>&gt;</span>
<a name="l00003"></a>00003
<a name="l00004"></a>00004 <span class="comment">// if Time-Source is "gettimeofday()" from sys/time.h</span>
<a name="l00005"></a>00005 <span class="comment">// surprisingly this works out of the box. and it seems to be a</span>
<a name="l00006"></a>00006 <span class="comment">// global synchronized time. no internal information how it is</span>
<a name="l00007"></a>00007 <span class="comment">// implemented was found so far, but I think its communicating</span>
<a name="l00008"></a>00008 <span class="comment">// with the PPU because there is no known instance on the SPU</span>
<a name="l00009"></a>00009 <span class="comment">// capable of handling this except the SPU timer library.</span>
<a name="l00010"></a>00010 <span class="comment">// so be carefull using this.</span>
<a name="l00011"></a>00011 <span class="preprocessor">#if defined(MOC_SPU_TIMESOURCE_TIMEOFDAY)</span>
<a name="l00012"></a>00012 <span class="preprocessor"></span><span class="preprocessor">#undef MOC_SPU_TIMESOURCE_SPUTIME</span>
<a name="l00013"></a>00013 <span class="preprocessor"></span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &lt;time.h&gt;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;sys/time.h&gt;</span>
<a name="l00016"></a>00016
<a name="l00017"></a>00017 <span class="keywordtype">double</span> <a class="code" href="../../d8/da6/group__environment__timer.html#g415b17505f06a12f26c6aa735d00158f" title="Returns a floating-point number of seconds, representing elapsed wall-clock time...">MOC_Wtime</a>(<span class="keywordtype">void</span>)
<a name="l00018"></a>00018 {
<a name="l00019"></a>00019 <span class="keyword">struct </span>timeval time;
<a name="l00020"></a>00020 gettimeofday(&amp;time, NULL);
<a name="l00021"></a>00021 <span class="keywordflow">return</span> ((<span class="keywordtype">double</span>) time.tv_sec) + ((double) time.tv_usec)
<a name="l00022"></a>00022 / ((double) 1000000.0);
<a name="l00023"></a>00023 }
<a name="l00024"></a>00024
<a name="l00025"></a>00025 <span class="comment">// if Time-Source is the SPU timer library</span>
<a name="l00026"></a>00026 <span class="comment">// this library seems to have prototype-status and its path isn't</span>
<a name="l00027"></a>00027 <span class="comment">// the default. therefore the sputimer-library needs to be explicitly</span>
<a name="l00028"></a>00028 <span class="comment">// linked to any MOC-application.</span>
<a name="l00029"></a>00029 <span class="preprocessor">#elif defined(MOC_SPU_TIMESOURCE_SPUTIME)</span>
<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#undef MOC_SPU_TIMESOURCE_TIMEOFDAY</span>
<a name="l00031"></a>00031 <span class="preprocessor"></span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &lt;spu_mfcio.h&gt;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &lt;spu_timer.h&gt;</span>
<a name="l00034"></a>00034
<a name="l00035"></a>00035 <span class="preprocessor">#define IMOC_TIMEBASE 79800000</span>
<a name="l00036"></a>00036 <span class="preprocessor"></span>
<a name="l00037"></a>00037 <span class="keywordtype">char</span> isTimerRunning = 0;
<a name="l00038"></a>00038
<a name="l00039"></a>00039 <span class="keywordtype">double</span> <a class="code" href="../../d8/da6/group__environment__timer.html#g415b17505f06a12f26c6aa735d00158f" title="Returns a floating-point number of seconds, representing elapsed wall-clock time...">MOC_Wtime</a>(<span class="keywordtype">void</span>)
<a name="l00040"></a>00040 {
<a name="l00041"></a>00041 <span class="keywordflow">if</span> (!isTimerRunning)
<a name="l00042"></a>00042 {
<a name="l00043"></a>00043 spu_slih_register (MFC_DECREMENTER_EVENT, spu_clock_slih);
<a name="l00044"></a>00044 spu_clock_start ();
<a name="l00045"></a>00045 isTimerRunning = 1;
<a name="l00046"></a>00046 }
<a name="l00047"></a>00047 <span class="keywordflow">return</span> ((<span class="keywordtype">double</span>)spu_clock_read()/((<span class="keywordtype">double</span>)IMOC_TIMEBASE));
<a name="l00048"></a>00048 }
<a name="l00049"></a>00049
<a name="l00050"></a>00050 <span class="comment">// if no time-source</span>
<a name="l00051"></a>00051 <span class="comment">// some dummy-functions</span>
<a name="l00052"></a>00052 <span class="preprocessor">#else</span>
<a name="l00053"></a>00053 <span class="preprocessor"></span>
<a name="l00054"></a><a class="code" href="../../d8/da6/group__environment__timer.html#g415b17505f06a12f26c6aa735d00158f">00054</a> <span class="keywordtype">double</span> <a class="code" href="../../d8/da6/group__environment__timer.html#g415b17505f06a12f26c6aa735d00158f" title="Returns a floating-point number of seconds, representing elapsed wall-clock time...">MOC_Wtime</a>(<span class="keywordtype">void</span>)
<a name="l00055"></a>00055 {
<a name="l00056"></a>00056 <span class="keywordflow">return</span> 0;
<a name="l00057"></a>00057 }
<a name="l00058"></a>00058
<a name="l00059"></a>00059 <span class="preprocessor">#endif</span>
<a name="l00060"></a>00060 <span class="preprocessor"></span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Thu Feb 12 13:49:47 2009 for MPI On Cell (Documentation) by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="../../doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>