<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div style="font-size: 16px; "><br></div><div style="font-size: 16px; ">Perhaps making admb type containers thread safe is a good place to start. This would make it easier to modify admb internally as well as allow end users to make their own applications concurrent.</div><div style="font-size: 16px; "><br></div><div style="font-size: 16px; ">I've started working on this issue for one of our staff. After profiling his model, I found nearly 70-80% of the runtime was in his user_function looping through a df1b2matrix and doing operations on its elements. In this particular case,</div><div style="font-size: 16px; ">admb is quite fast and is really just waiting for user_function evaluations(nested for loops). This is the perfect location for multi-threading.</div><div style="font-size: 16px; "><br></div><div style="font-size: 16px; "><br></div><div style="font-size: 16px; ">At the moment I'm working on a thread safe wrapper for df1b2matrix in order to speed up this particular model. This should be all that is needed for this particular case, but I suspect this cause may be a common.</div><div style="font-size: 16px; "><br></div><div style="font-size: 16px; "><br></div><div style="font-size: 16px; ">Attached is a simple platform independent threading library. </div><div style="font-size: 16px; "><br></div><div style="font-size: 16px; "><br></div><div style="font-size: 16px; ">My strategy for making df1b2matrix thread safe is to wrap it as follows:</div><div style="font-size: 16px; "><br></div><div style="font-size: 16px; "><br></div><div style="font-size: 16px; "><pre style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: Monospaced; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; position: static; z-index: auto; "><span class="Apple-style-span" style="font-weight: normal; "> </span>11 <span class="preprocessor-keyword-directive" style="color: rgb(0, 155, 0); ">#</span><span class="preprocessor-keyword-directive" style="color: rgb(0, 155, 0); ">include</span> <span class="preprocessor-system-include-literal" style="color: rgb(206, 123, 0); "><admodel.h></span></pre><pre style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: Monospaced; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; position: static; z-index: auto; "> 12 <span class="preprocessor-keyword-directive" style="color: rgb(0, 155, 0); ">#</span><span class="preprocessor-keyword-directive" style="color: rgb(0, 155, 0); ">include</span> <span class="preprocessor-system-include-literal" style="color: rgb(206, 123, 0); ">"Threads.hpp"</span>
13
14
15 <span class="keyword-directive" style="color: rgb(0, 0, 230); ">namespace</span> admb {
16</pre><pre style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: Monospaced; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; position: static; z-index: auto; ">17 <span class="keyword-directive" style="color: rgb(0, 0, 230); ">class</span> ts_df1b2matrix {</pre><pre style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: Monospaced; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; position: static; z-index: auto; "><span class="Apple-style-span"> 18
19 <span class="keyword-directive" style="color: rgb(0, 0, 230); ">int</span> <span class="ST0" style="font-family: Monospaced; font-weight: bold; ">allocated</span>(<span class="keyword-directive" style="color: rgb(0, 0, 230); ">void</span>) {
20 noaa::threads::Lock(<span class="ST1" style="color: rgb(0, 153, 0); ">mutex_</span>);
21 <span class="ST1" style="color: rgb(0, 153, 0); ">df1b2matrix_</span>.allocated();
22 }
23
24 <span class="keyword-directive" style="color: rgb(0, 0, 230); ">void</span> <span class="ST0" style="font-family: Monospaced; font-weight: bold; ">initialize</span>(<span class="keyword-directive" style="color: rgb(0, 0, 230); ">void</span>) {
25 noaa::threads::Lock(<span class="ST1" style="color: rgb(0, 153, 0); ">mutex_</span>);
26 <span class="ST1" style="color: rgb(0, 153, 0); ">df1b2matrix_</span>.initialize();
27
28 }
29
30 ~<b>ts_</b><span class="ST0" style="font-family: Monospaced; font-weight: bold; ">df1b2matrix</span>() {
31 noaa::threads::Lock(<span class="ST1" style="font-weight: normal; color: rgb(0, 153, 0); ">mutex_</span>);
32 ~<span class="ST1" style="font-weight: normal; color: rgb(0, 153, 0); ">df1b2matrix_</span>;
33 }
34
35 <span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">int</span> <span class="ST0" style="font-family: Monospaced; font-weight: bold; ">rowmin</span>(<span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">void</span>) <span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">const</span> {
36 noaa::threads::Lock(<span class="ST1" style="font-weight: normal; color: rgb(0, 153, 0); ">mutex_</span>);
37 <span class="ST1" style="font-weight: normal; color: rgb(0, 153, 0); ">df1b2matrix_</span>.rowmin();
38 }
39
40 <span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">int</span> <span class="ST0" style="font-family: Monospaced; font-weight: bold; ">indexmin</span>(<span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">void</span>) <span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">const</span> {
41 noaa::threads::Lock(<span class="ST1" style="font-weight: normal; color: rgb(0, 153, 0); ">mutex_</span>);
42 <span class="ST1" style="font-weight: normal; color: rgb(0, 153, 0); ">df1b2matrix_</span>.indexmin();
43 }
44
45 <span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">int</span> <span class="ST0" style="font-family: Monospaced; font-weight: bold; ">indexmax</span>(<span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">void</span>) <span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">const</span> {
46 noaa::threads::Lock(<span class="ST1" style="font-weight: normal; color: rgb(0, 153, 0); ">mutex_</span>);
47 <span class="ST1" style="font-weight: normal; color: rgb(0, 153, 0); ">df1b2matrix_</span>.indexmax();
48 }
49
50 <span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">int</span> <span class="ST0" style="font-family: Monospaced; font-weight: bold; ">rowmax</span>(<span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">void</span>) <span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">const</span> {
51 noaa::threads::Lock(<span class="ST1" style="font-weight: normal; color: rgb(0, 153, 0); ">mutex_</span>);
52 <span class="ST1" style="font-weight: normal; color: rgb(0, 153, 0); ">df1b2matrix_</span>.rowmax();
53 }
54
55 <span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">int</span> <span class="ST0" style="font-family: Monospaced; font-weight: bold; ">size</span>(<span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">void</span>) <span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">const</span> {
56 noaa::threads::Lock(<span class="ST1" style="font-weight: normal; color: rgb(0, 153, 0); ">mutex_</span>);
57 <span class="ST1" style="font-weight: normal; color: rgb(0, 153, 0); ">df1b2matrix_</span>.size();
58 }
59
60 <span class="ST0" style="font-family: Monospaced; font-weight: bold; ">ts_df1b2matrix</span>(<span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">int</span> nrl, <span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">int</span> nrh) {
61 noaa::threads::Lock(<span class="ST1" style="font-weight: normal; color: rgb(0, 153, 0); ">mutex_</span>);
62 <span class="ST1" style="font-weight: normal; color: rgb(0, 153, 0); ">df1b2matrix_</span>(nrl, nrh);
63 }
64
65 <span class="ST0" style="font-family: Monospaced; font-weight: bold; ">ts_df1b2matrix</span>(<span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">const</span> df1b2matrix &other) {
66 noaa::threads::Lock(<span class="ST1" style="font-weight: normal; color: rgb(0, 153, 0); ">mutex_</span>);
67 <span class="ST1" style="font-weight: normal; color: rgb(0, 153, 0); ">df1b2matrix_</span>(other);
68 }
69
70 <span class="ST0" style="font-family: Monospaced; font-weight: bold; ">ts_df1b2matrix</span>(<span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">const</span> ts_df1b2matrix &<span class="ST2" style="font-weight: normal; background-color: rgb(236, 235, 163); ">other</span>) {
71 noaa::threads::Lock(<span class="ST1" style="font-weight: normal; color: rgb(0, 153, 0); ">mutex_</span>);
72 noaa::threads::Lock2(<span class="ST2" style="font-weight: normal; background-color: rgb(236, 235, 163); ">other</span>.mutex_);
73 <span class="ST1" style="font-weight: normal; color: rgb(0, 153, 0); ">df1b2matrix_</span>(<span class="ST2" style="font-weight: normal; background-color: rgb(236, 235, 163); ">other</span>.<span class="ST1" style="font-weight: normal; color: rgb(0, 153, 0); ">df1b2matrix_</span>);
74 }
75
76 <span class="ST0" style="font-family: Monospaced; font-weight: bold; ">ts_df1b2matrix</span>(<span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">int</span> nrl, <span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">int</span> nrh, <span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">const</span> index_type &ncl, <span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">const</span> index_type &nch) {
77 noaa::threads::Lock(<span class="ST1" style="font-weight: normal; color: rgb(0, 153, 0); ">mutex_</span>);
78 df1b2matrix(nrl, nrh, ncl, nch);
79 }
80
81 </span> <span class="ST0" style="font-family: Monospaced; font-weight: bold; ">ts_df1b2matrix</span><span class="Apple-style-span">& <span class="ST3" style="color: rgb(0, 0, 230); font-family: Monospaced; font-weight: bold; ">operator</span><span class="ST0" style="font-family: Monospaced; font-weight: bold; ">=</span>(<span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">const</span> df3_one_matrix &other) {
82 noaa::threads::Lock(<span class="ST1" style="font-weight: normal; color: rgb(0, 153, 0); ">mutex_</span>);
83 <span class="keyword-directive" style="font-weight: normal; color: rgb(0, 0, 230); ">this</span>-><span class="ST1" style="font-weight: normal; color: rgb(0, 153, 0); ">df1b2matrix_</span> = other;
84 }
85 </span></pre><pre style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: Monospaced; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; position: static; z-index: auto; ">.</pre><pre style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: Monospaced; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; position: static; z-index: auto; ">.</pre><pre style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: Monospaced; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; position: static; z-index: auto; ">.</pre><pre style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: Monospaced; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; position: static; z-index: auto; ">.</pre><pre style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: Monospaced; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; position: static; z-index: auto; ">
162
163 <span class="keyword-directive" style="color: rgb(0, 0, 230); ">private</span>:
164 <span class="keyword-directive" style="color: rgb(0, 0, 230); ">mutable</span> noaa::threads::Mutex <span class="ST1" style="color: rgb(0, 153, 0); ">mutex_</span>;
165 df1b2matrix <span class="ST1" style="color: rgb(0, 153, 0); ">df1b2matrix_</span>;
166
167
168 };</pre><div><br></div><div><br></div></div><div style="font-size: 16px; "><pre style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: Monospaced; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; position: static; z-index: auto; ">The call "noaa::threads::Lock(<span class="ST1" style="color: rgb(0, 153, 0); ">mutex_</span>); " will lock the function and then unlock it as it goes out of scope.</pre><pre style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: Monospaced; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; position: static; z-index: auto; ">I'll be happy to pass the finished product for review.</pre><div><br></div></div><div style="font-size: 16px; "><br></div><div style="font-size: 16px; "><br></div><div style="font-size: 16px; "><br></div><div style="font-size: 16px; "></div></body></html>