Text archives Help
- From: abe@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r536 - branches/itanium2/StandAlone
- Date: Thu, 8 Sep 2005 18:03:27 -0600 (MDT)
Author: abe
Date: Thu Sep 8 18:03:22 2005
New Revision: 536
Added:
branches/itanium2/StandAlone/barrier_test.cc
Modified:
branches/itanium2/StandAlone/CMakeLists.txt
Log:
Added bin/barrier_test to measure SCIRun barrier performance
Modified: branches/itanium2/StandAlone/CMakeLists.txt
==============================================================================
--- branches/itanium2/StandAlone/CMakeLists.txt (original)
+++ branches/itanium2/StandAlone/CMakeLists.txt Thu Sep 8 18:03:22 2005
@@ -9,6 +9,11 @@
SCIRun_Core)
TARGET_LINK_LIBRARIES(manta ${CMAKE_THREAD_LIBS_INIT}
- ${OPENGL_LIBRARIES}
- ${X11_LIBRARIES}
- -lm)
+ ${OPENGL_LIBRARIES}
+ ${X11_LIBRARIES}
+ -lm)
+
+
+ADD_EXECUTABLE(barrier_test barrier_test.cc)
+TARGET_LINK_LIBRARIES(barrier_test SCIRun_Core
+ ${CMAKE_THREAD_LIBS_INIT})
\ No newline at end of file
Added: branches/itanium2/StandAlone/barrier_test.cc
==============================================================================
--- (empty file)
+++ branches/itanium2/StandAlone/barrier_test.cc Thu Sep 8 18:03:22
2005
@@ -0,0 +1,160 @@
+
+
+/*
+ For more information, please see:
http://software.sci.utah.edu
+
+ The MIT License
+
+ Copyright (c) 2005
+ Silicon Graphics Inc. Mountain View California.
+
+ License for the specific language governing rights and limitations under
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+// abe@sgi.com
+
+#include <SCIRun/Core/Thread/Time.h>
+#include <SCIRun/Core/Thread/Thread.h>
+#include <SCIRun/Core/Thread/Runnable.h>
+#include <SCIRun/Core/Thread/Barrier.h>
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <iostream>
+#include <string>
+
+#include <pthread.h>
+
+using namespace SCIRun;
+using std::string;
+
+class BarrierTest : public Runnable {
+public:
+ struct Setup {
+ int proc;
+ int np;
+
+ Barrier *barrier;
+ double max_seconds;
+ };
+
+private:
+ Setup *remote_copy; // Remote copy allocated by the driving thread.
+ Setup *params; // Local copy allocated during run() by the new thread.
+
+public:
+ // Constructor.
+ BarrierTest( Setup *remote_copy_ ) : remote_copy( remote_copy_ ) { };
+
+ // Thread method.
+ virtual void run() {
+
+
/////////////////////////////////////////////////////////////////////////////////////////////
+ // Allocate local memory.
+ params = new Setup();
+
+ // Copy setup to local memory.
+ (*params) = (*remote_copy);
+
+
/////////////////////////////////////////////////////////////////////////////////////////////
+ // Wait for everyone to start up.
+ params->barrier->wait( params->np );
+
+ // Record the start time.
+ if (params->proc == 0) {
+
+ double start_time = Time::currentSeconds();
+ long long n_barriers = 0;
+
+ while ((Time::currentSeconds() - start_time) < params->max_seconds) {
+ params->barrier->wait( params->np );
+ ++n_barriers;
+ }
+
+ double end_time = Time::currentSeconds();
+
+ std::cout << "np: " << params->np << " "
+ << n_barriers << " in " << (end_time-start_time) << "
seconds. "
+ << (double)n_barriers/(end_time-start_time) << " barriers per
second." << std::endl;
+
+ Thread::exitAll( 0 );
+ exit(0);
+ }
+ else {
+ for (;;) {
+ params->barrier->wait( params->np );
+ }
+ }
+ }
+};
+
+int main (int argc, char **argv) {
+
+ // Check for args.
+ int np = 1;
+ double seconds = 10;
+
+ for (int i=0;i<argc;++i) {
+ string arg = argv[i];
+
+ if ((arg == "-np") && ((i+1) < argc)) {
+ np = atoi( argv[++i] );
+ }
+ else if ((arg == "-seconds") && ((i+1) < argc)) {
+ seconds = atof( argv[++i] );
+ }
+ }
+
+ // Create the barrier
+ Barrier barrier("barrier");
+
+ // Create setup params.
+
+ BarrierTest::Setup *remote_setup = new BarrierTest::Setup[np];
+ for (int i=0;i<np;++i) {
+ remote_setup[i].proc = i;
+ remote_setup[i].np = np;
+ remote_setup[i].barrier = &barrier;
+ remote_setup[i].max_seconds = seconds;
+ }
+
+ // Create the worker Runnables.
+ BarrierTest **runnables = new BarrierTest *[np];
+
+ for (int i=0;i<np;++i) {
+ runnables[i] = new BarrierTest( &(remote_setup[i]) );
+ }
+
+ // Create the threads.
+ char name[32];
+
+ Thread **threads = new Thread *[np];
+ for (int i=1;i<np;++i) {
+ sprintf(name,"Worker: %d", i);
+ threads[i] = new Thread( runnables[i], name );
+ }
+
+ // Run the first thread's work in this thread.
+ runnables[0]->run();
+}
+
+
- [MANTA] r536 - branches/itanium2/StandAlone, abe, 09/08/2005
Archive powered by MHonArc 2.6.16.