PLearn 0.1
TestClientCommand.cc
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // TestClientCommand.cc
00004 //
00005 // Copyright (C) 2007 Xavier Saint-Mleux, Apstat Technologies, inc.
00006 // 
00007 // Redistribution and use in source and binary forms, with or without
00008 // modification, are permitted provided that the following conditions are met:
00009 // 
00010 //  1. Redistributions of source code must retain the above copyright
00011 //     notice, this list of conditions and the following disclaimer.
00012 // 
00013 //  2. Redistributions in binary form must reproduce the above copyright
00014 //     notice, this list of conditions and the following disclaimer in the
00015 //     documentation and/or other materials provided with the distribution.
00016 // 
00017 //  3. The name of the authors may not be used to endorse or promote
00018 //     products derived from this software without specific prior written
00019 //     permission.
00020 // 
00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
00024 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00025 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00026 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00027 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00028 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00029 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031 // 
00032 // This file is part of the PLearn library. For more information on the PLearn
00033 // library, go to the PLearn Web site at www.plearn.org
00034 
00035 // Authors: Xavier Saint-Mleux
00036 
00040 #include "TestClientCommand.h"
00041 #include <plearn/misc/PLearnService.h>
00042 #include <plearn/io/pl_log.h>
00043 #include <plearn/vmat/MemoryVMatrix.h>
00044 #include <plearn/base/PDateTime.h>
00045 #include <plearn/base/ProgressBar.h>
00046 
00047 namespace PLearn {
00048 using namespace std;
00049 
00051 PLearnCommandRegistry TestClientCommand::reg_(new TestClientCommand);
00052 
00053 TestClientCommand::TestClientCommand():
00054     PLearnCommand("testclient",
00055 
00056                   "Launches plearn in test client mode",
00057 
00058                   "testclient\n"
00059                   "  Launches plearn in test client mode \n"
00060                   " \n"
00061         )
00062 {}
00063 
00064 
00066 void TestClientCommand::run(const vector<string>& args)
00067 {
00068 
00069     cout << "test client run" << endl;
00070     
00071 
00072     PLearnService& ps(PLearnService::instance()); 
00073   
00074     int ns= ps.availableServers();
00075     TVec<PP<RemotePLearnServer> > ss= ps.reserveServers(ns);
00076 
00077 
00078     cout << "test client has servers" << endl;
00079 
00080     TVec<int> objids(ns);
00081 
00082     for(int i= 0; i < ns; ++i)
00083     {
00084         //ss[i]->newObjectAsync(1, string("MemoryVMatrix(width= 5000, length= 7000)"));
00085         //ss[i]->newObjectAsync(string("MemoryVMatrix(width= 5000, length= 7000)"));
00086         objids[i]= ss[i]->newObject(string("MemoryVMatrix(width= 5000, length= 7000)"));
00087         cerr << "NEW OBJ " << i << '-' << objids[i] << endl;
00088     }
00089 /*
00090     for(int i= 0; i < ns; ++i)
00091     {
00092         int j= ps.watchServers(ss, PLearnService::log_callback, PLearnService::progress_callback);
00093         cout << "result 1 from " << j << " at " << PDateTime::currentLocalTime() << endl;
00094         ss[j]->getResults(objids[j]);
00095     }
00096 */
00097     for(int i= 0; i < ns; ++i)
00098         ss[i]->callMethod(objids[i], "fill", 3.21*static_cast<real>(i+1));
00099 
00100     for(int i= 0; i < ns; ++i)
00101     {
00102 /*
00103         int j= ps.watchServers(ss, PLearnService::log_callback, PLearnService::progress_callback);
00104         cout << "result 2 from " << j << " at " << PDateTime::currentLocalTime() << endl;
00105         ss[j]->getResults();
00106 */
00107         ps.waitForResult()->getResults();
00108     }
00109 
00110     cout << "before getRow" << endl;
00111 
00112     for(int i= 0; i < ns; ++i)
00113         ss[i]->callMethod(objids[i], "getRow", 3);
00114 
00115     cout << "after getRow" << endl;
00116 
00117     for(int i= 0; i < ns; ++i)
00118     {
00119         cout << "bws " << i << endl;
00120 
00121         int j= ps.watchServers(ss, PLearnService::log_callback, PLearnService::progress_callback);
00122         cout << "result 3 from " << j << " at " << PDateTime::currentLocalTime() << endl;
00123         Vec vv;
00124 
00125         cout << "getting it" << endl;
00126 
00127         ss[j]->getResults(vv);
00128 
00129         cout << "got it" << endl;
00130 
00131         pout << '\t' << vv[0] << endl;
00132     }
00133 
00134     cout << "before call dot" << endl;
00135 
00136     for(int i= 0; i < ns; ++i)
00137         ss[i]->callMethod(objids[i], "dot", 1, 3, 4500);
00138 
00139     cout << "after call dot" << endl;
00140 
00141     for(int i= 0; i < ns; ++i)
00142     {
00143         int j= ps.watchServers(ss, PLearnService::log_callback, PLearnService::progress_callback);
00144         cout << "result 4 from " << j << " at " << PDateTime::currentLocalTime() << endl;
00145         real x;
00146         ss[j]->getResults(x);
00147         cout << endl << '=' << x << endl;
00148     }
00149 
00150     cout << "before call save" << endl;
00151 
00152     for(int i= 0; i < ns; ++i)
00153         ss[i]->callMethod(objids[i], "savePMAT", string("/home/saintmlx/testclient/mat")+tostring(i)+string(".pmat"));
00154 
00155     cout << "after call save" << endl;
00156 
00157     for(int i= 0; i < ns; ++i)
00158     {
00159         int j= ps.watchServers(ss, PLearnService::log_callback, PLearnService::progress_callback);
00160         cout << "result 5 from " << j << " at " << PDateTime::currentLocalTime() << endl;
00161         ss[j]->getResults();
00162     }
00163 
00164     cout << "before delete" << endl;
00165 
00166     for(int i= 0; i < ns; ++i)
00167         ss[i]->deleteObjectAsync(objids[i]);
00168 
00169     cout << "after delete" << endl;
00170 
00171     for(int i= 0; i < ns; ++i)
00172     {
00173         int j= ps.watchServers(ss, PLearnService::log_callback, PLearnService::progress_callback);
00174         cout << "result 6 from " << j << " at " << PDateTime::currentLocalTime() << endl;
00175         ss[j]->getResults();
00176     }
00177 
00178 }
00179 
00180 } // end of namespace PLearn
00181 
00182 
00183 /*
00184   Local Variables:
00185   mode:c++
00186   c-basic-offset:4
00187   c-file-style:"stroustrup"
00188   c-file-offsets:((innamespace . 0)(inline-open . 0))
00189   indent-tabs-mode:nil
00190   fill-column:79
00191   End:
00192 */
00193 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines