00001 /** @file pvminterface.h */ 00002 /* 00003 * Copyright (C) 2002 Laird Breyer 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 * 00019 * Author: Laird Breyer <laird@lbreyer.com> 00020 */ 00021 00022 #ifndef _PVM_INTERFACE_H 00023 #define _PVM_INTERFACE_H 00024 00025 #ifdef DISTRIBUTED_COMPUTING 00026 // don't inclued anything above this line 00027 #include <pvm3.h> 00028 #endif 00029 00030 #include "basictypes.h" 00031 #include <stdexcept> 00032 00033 #define PVMINTERFACE_NAMELEN 20 00034 #define PVMINTERFACE_SENDINFO 1 00035 #define PVMINTERFACE_SENDCOMMAND 2 00036 #define PVMINTERFACE_SENDLEAFUPD 3 00037 00038 /// Contains vital task information. 00039 struct PVMTaskInfo { 00040 int tid; 00041 uint32 start_id; 00042 uint32 stop_id; 00043 char name[PVMINTERFACE_NAMELEN+1]; 00044 }; 00045 00046 /// Handles communication between Talker and PVM 00047 class PVMInterface { 00048 public: 00049 PVMInterface(const char* name, 00050 bool ismaster, int ntasks, 00051 int stardid, int stopid) throw (runtime_error); 00052 ~PVMInterface(); 00053 00054 void BroadcastCommand(const char* commandline) throw (runtime_error); 00055 void SendCommand(int taskno, const char* commandline) throw (runtime_error); 00056 void GetCommandWithTimeout(char* commandline) throw (runtime_error); 00057 00058 bool MessagePending(); 00059 int LastMessageOriginator(); 00060 00061 bool AllStandby() throw (runtime_error); 00062 void LeaveStandbyGroup(); 00063 void JoinStandbyGroup(); 00064 00065 int FindTask(uint32 id); 00066 const char* Name(int k); 00067 int NumberOfTasks() 00068 { return num_tasks; } 00069 int NumberOfOtherTasks() 00070 { return num_tasks - 1; } 00071 uint32 StartID(int k) 00072 { assert(k < num_tasks - 1); return tasklist[k].start_id; } 00073 uint32 StopID(int k) 00074 { assert(k < num_tasks - 1); return tasklist[k].stop_id; } 00075 00076 bool IsMaster() 00077 { return is_master; } 00078 bool IsSlave() 00079 { return !(is_master || (num_tasks > 0)); } 00080 00081 void GetLeafCounts(unsigned int* countsarray, uint32* size) throw (runtime_error); 00082 void SendLeafCounts(int tid, unsigned int* countsarray, uint32 size) throw (runtime_error); 00083 00084 private: 00085 PVMTaskInfo myinfo; 00086 bool is_master; 00087 int num_tasks; 00088 00089 PVMTaskInfo *tasklist; 00090 00091 int last_message_tid; 00092 int last_message_size; 00093 int last_message_msgtag; 00094 }; 00095 00096 #endif