RepastHPC  2.3.1
AgentImporterExporter.h
1 /*
2  * Repast for High Performance Computing (Repast HPC)
3  *
4  * Copyright (c) 2010 Argonne National Laboratory
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with
8  * or without modification, are permitted provided that the following
9  * conditions are met:
10  *
11  * Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  *
14  * Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * Neither the name of the Argonne National Laboratory nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TRUSTEES OR
26  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  * Created on: Jun 14, 2011
35  * Author: John T. Murphy
36  */
37 
38 #ifndef AGENTIMPORTEREXPORTER_H_
39 #define AGENTIMPORTEREXPORTER_H_
40 
41 #include <map>
42 #include <set>
43 #include <list>
44 
45 #include "AgentRequest.h"
46 #include "AgentId.h"
47 #include "AgentStatus.h"
48 #include "mpi_constants.h"
49 
50 /*
51  * If you wish to select the default
52  * kind of Importer/Exporter, use one
53  * of the valid values here (default
54  * if not specified is 1):
55  *
56  * 1 = COUNT_LIST
57  * 2 = COUNT_SET
58  * 3 = LIST
59  * 4 = SET
60  * 5 = MAP(int)
61  */
62 //#define DEFAULT_IMPORTER_EXPORTER 5
63 
64 /*
65  * If defined, allow multiple importer/exporter
66  * instances managing distinct sets of agents
67  */
68 #define SHARE_AGENTS_BY_SET
69 
70 /*
71  * If you wish to allow a single cancellation to be used
72  * to cancel all of an agent's requests (for semantics
73  * where multiple cancellations would ordinarily be
74  * required), define this flag
75  */
76 //#define ALLOW_FULL_AGENT_REQUEST_CANCELLATION
77 
78 
79 /* Preprocessor configuration */
80 
81 #ifndef DEFAULT_IMPORTER_EXPORTER
82  #define DEFAULT_IMPORTER_EXPORTER 4
83 #endif
84 
85 #if DEFAULT_IMPORTER_EXPORTER < 1 || DEFAULT_IMPORTER_EXPORTER > 5
86  #error "Invalid value used for default Importer_Exporter"
87 #endif
88 
89 // If you are not permitting agent request by set,
90 // then only one of the importer_exporters should be compiled
91 // (The one chosen as the default)
92 #ifndef SHARE_AGENTS_BY_SET
93 
94  #if DEFAULT_IMPORTER_EXPORTER != 1 && !defined OMIT_IMPORTER_EXPORTER_COUNT_LIST
95  #define OMIT_IMPORTER_EXPORTER_COUNT_LIST
96  #endif
97 
98  #if DEFAULT_IMPORTER_EXPORTER != 2 && !defined OMIT_IMPORTER_EXPORTER_COUNT_SET
99  #define OMIT_IMPORTER_EXPORTER_COUNT_SET
100  #endif
101 
102  #if DEFAULT_IMPORTER_EXPORTER != 3 && !defined OMIT_IMPORTER_EXPORTER_LIST
103  #define OMIT_IMPORTER_EXPORTER_LIST
104  #endif
105 
106  #if DEFAULT_IMPORTER_EXPORTER != 4 && !defined OMIT_IMPORTER_EXPORTER_SET
107  #define OMIT_IMPORTER_EXPORTER_SET
108  #endif
109 
110  #if DEFAULT_IMPORTER_EXPORTER != 5 && !defined OMIT_IMPORTER_EXPORTER_MAP_int
111  #define OMIT_IMPORTER_EXPORTER_MAP_int
112  #endif
113 
114 #endif
115 
116 
117 
118 // Cannot set both 'default' and 'omit'; setting one
119 // as default overrides the omit
120 #if DEFAULT_IMPORTER_EXPORTER == 1
121  #define DEFAULT_IMPORTER_EXPORTER_CLASS ImporterExporter_COUNT_LIST
122  #define DEFAULT_ENUM_SYMBOL COUNT_LIST
123  #undef OMIT_IMPORTER_EXPORTER_COUNT_LIST
124 #endif
125 
126 #if DEFAULT_IMPORTER_EXPORTER == 2
127  #define DEFAULT_IMPORTER_EXPORTER_CLASS ImporterExporter_COUNT_SET
128  #define DEFAULT_ENUM_SYMBOL COUNT_SET
129  #undef OMIT_IMPORTER_EXPORTER_COUNT_SET
130 #endif
131 
132 #if DEFAULT_IMPORTER_EXPORTER == 3
133  #define DEFAULT_IMPORTER_EXPORTER_CLASS ImporterExporter_LIST
134  #define DEFAULT_ENUM_SYMBOL LIST
135  #undef OMIT_IMPORTER_EXPORTER_LIST
136 #endif
137 
138 #if DEFAULT_IMPORTER_EXPORTER == 4
139  #define DEFAULT_IMPORTER_EXPORTER_CLASS ImporterExporter_SET
140  #define DEFAULT_ENUM_SYMBOL SET
141  #undef OMIT_IMPORTER_EXPORTER_SET
142 #endif
143 
144 #if DEFAULT_IMPORTER_EXPORTER == 5
145  #define DEFAULT_IMPORTER_EXPORTER_CLASS ImporterExporter_MAP_int
146  #define DEFAULT_ENUM_SYMBOL MAP_int
147  #undef OMIT_IMPORTER_EXPORTER_MAP_int
148 #endif
149 
150 
151 
152 #ifdef SHARE_AGENTS_BY_SET
153 // This enum is useful when requests by set are allowed
154 // Result of this construction is enum AGENT_IMPORTER_EXPORTER_TYPE{ Default[, non-default1][, non-default2] }, with non-compiled classes omitted
155 enum AGENT_IMPORTER_EXPORTER_TYPE{ DEFAULT_ENUM_SYMBOL
156 #if !defined OMIT_IMPORTER_EXPORTER_COUNT_LIST && DEFAULT_IMPORTER_EXPORTER != 1
157 , COUNT_LIST
158 #endif
159 #if !defined OMIT_IMPORTER_EXPORTER_COUNT_SET && DEFAULT_IMPORTER_EXPORTER != 2
160 , COUNT_SET
161 #endif
162 #if !defined OMIT_IMPORTER_EXPORTER_LIST && DEFAULT_IMPORTER_EXPORTER != 3
163 , LIST
164 #endif
165 #if !defined OMIT_IMPORTER_EXPORTER_SET && DEFAULT_IMPORTER_EXPORTER != 4
166 , SET
167 #endif
168 #if !defined OMIT_IMPORTER_EXPORTER_MAP_int && DEFAULT_IMPORTER_EXPORTER != 5
169 , MAP_int
170 #endif
171 };
172 
173 #define DEFAULT_AGENT_REQUEST_SET "__Default_Agent_Request_Set__"
174 
175 #endif
176 
177 /* END PREPROCESSOR */
178 
179 
180 #define REQUEST_AGENTS_ALL "AGENTS_FROM_ALL_IMPORTER_EXPORTERS"
181 
182 
183 namespace repast{
184 
185 
186 #ifndef SHARE_AGENTS_BY_SET
187 typedef std::map<int, AgentRequest*> AgentExporterInfo;
188 #else
189 typedef std::map<std::string, std::map<int, AgentRequest*>* > AgentExporterInfo;
190 #endif
191 
200 private:
201  AgentExporterInfo empty; // Used as dummy for sending empty data
202  std::map<int, AgentExporterInfo* > data;
203 
204 #ifdef SHARE_AGENTS_BY_SET
205  std::string selectedSet;
206 #endif
207 
208 public:
211 
217  void addData(const AgentId& id, const int destProc, const int sourceProc,
218  const int numberOfCopies = 1);
219 
224  AgentExporterInfo* dataForProc(int destProc);
225 
229  void clear();
230 
235  void removeAllDataForAgent(AgentId& id);
236 
237 
238 #ifdef SHARE_AGENTS_BY_SET
239 
244  void selectSet(std::string setName);
245 #endif
246 
247 };
248 
249 
250 
251 
252 /* Importers */
253 
254 #ifdef ALLOW_FULL_AGENT_REQUEST_CANCELLATION
255 
260 void markIdAsFullCancellation(AgentId& id){
261  id.currentRank(((-1) * id.currentRank()) - 1);
262 }
263 
274 bool checkForFullCancellation(AgentId& id){
275  if(id.currentRank() < 0){
276  id.currentRank((id.currentRank() + 1) * (-1));
277  return true;
278  }
279  else return false;
280 }
281 #endif
282 
283 
284 
285 /* IMPORTER */
286 
296 protected:
297  // Each child implementation is required to maintain this list
298  std::set<int> exportingProcesses;
299 
300 public:
301 
303  virtual ~AbstractImporter();
304 
309  virtual const std::set<int>& getExportingProcesses(){ return exportingProcesses; }
310 
319  virtual void registerOutgoingRequests(AgentRequest &req) = 0;
320 
326  virtual void importedAgentIsRemoved(const AgentId& id) = 0;
327 
333  virtual void importedAgentIsMoved(const AgentId& id, int newProcess) = 0;
334 
339 
343  virtual std::string getReport() = 0;
344 
345  virtual void getSetOfAgentsBeingImported(std::set<AgentId>& set) = 0;
346 
347  virtual void clear(){
348  exportingProcesses.clear();
349  }
350 };
351 
352 
353 #if !defined OMIT_IMPORTER_EXPORTER_COUNT_LIST || \
354  !defined OMIT_IMPORTER_EXPORTER_COUNT_SET
355 
365 
366 private:
367  std::map<int, int> sources;
368  void incrementCount(int sourceProcess);
369  void decrementCount(int sourceProcess);
370 
371 public:
372  Importer_COUNT();
373  virtual ~Importer_COUNT();
374 
375  virtual void registerOutgoingRequests(AgentRequest &req);
376  virtual void importedAgentIsRemoved(const AgentId& id);
377  virtual void importedAgentIsMoved(const AgentId& id, int newProcess);
378 
379  virtual std::string getReport();
380  virtual void getSetOfAgentsBeingImported(std::set<AgentId>& set);
381 };
382 #endif
383 
384 #ifndef OMIT_IMPORTER_EXPORTER_LIST
385 
401 
402 private:
403  std::map<int, std::list<AgentId>* > sources;
404 
405  // Inline helper functions to manage the internal recordkeeping
406 
407  // Gets the record associated with the specified other process;
408  // if none exists, one is created. 'exportingProcesses' is updated
409  inline std::list<AgentId>* getRecord(int rank);
410 
411  // Removes all the entries for a given agent from the specified record;
412  // Returns the number of entries removed
413  // Also: Invokes 'checkRecord'
414  inline int removeAll(const AgentId& id, std::list<AgentId>* record, int rank);
415 
416  // Removes one entry for a given ID (passes through to removeId by position)
417  inline void removeID(AgentId& id, std::list<AgentId>* record, int rank);
418 
419  // Removes the entry at the specified position in the record list.
420  // Also: Invokes 'checkRecord'
421  inline void removeID(std::list<AgentId>::iterator idPosition, std::list<AgentId>* record, int rank);
422 
423  // Checks the length of this record; if the record is now empty,
424  // it is removed from the map (and exportingProcesses is updated)
425  inline void checkRecord(std::list<AgentId>* record, int rank);
426 
427 public:
428  Importer_LIST();
429  ~Importer_LIST();
430 
431  virtual void registerOutgoingRequests(AgentRequest& req);
432  virtual void importedAgentIsRemoved(const AgentId& id);
433  virtual void importedAgentIsMoved(const AgentId& id, int newProcess);
434 
435  virtual std::string getReport();
436  virtual void getSetOfAgentsBeingImported(std::set<AgentId>& set);
437 
438  virtual void clear(){
439  AbstractImporter::clear();
440  sources.clear();
441  }
442 };
443 #endif
444 
445 
446 #ifndef OMIT_IMPORTER_EXPORTER_SET
447 
459 private:
460  std::map<int, std::set<AgentId>* > sources;
461 
462  // Helper functions to manage internal bookkeeping
463 
464  // Gets the record associated with the specified other
465  // rank. If none exists, one is created (and exportingProcesses
466  // is updated).
467  inline std::set<AgentId>* getRecord(int rank);
468 
469  // Removes an ID from the specified set.
470  // If this results in an actual removal, will return 1; if not,
471  // will return zero. AgentID will not be in map after operation.
472  // Also: Invokes checkRecord
473  inline int removeID(const AgentId& id, std::set<AgentId>* record, int rank);
474 
475  // Checks the size of the record passed; if zero, deletes it from
476  // the map and updates exportingProcesses
477  inline void checkRecord(std::set<AgentId>* record, int rank);
478 
479 public:
480  Importer_SET();
481  ~Importer_SET();
482 
483  virtual void registerOutgoingRequests(AgentRequest& req);
484  virtual void importedAgentIsRemoved(const AgentId& id);
485  virtual void importedAgentIsMoved(const AgentId& id, int newProcess);
486 
487  virtual std::string getReport();
488  virtual void getSetOfAgentsBeingImported(std::set<AgentId>& set);
489  virtual void clear(){
490  AbstractImporter::clear();
491  sources.clear();
492  }
493 };
494 #endif
495 
496 
497 #ifndef OMIT_IMPORTER_EXPORTER_MAP_int
498 
511 private:
512  std::map<int, std::map<AgentId, int>* > sources;
513 
514  // Helper functions to manage internal bookkeeping
515 
516  // Gets the record associated with the specified rank
517  // If one does not exist, it is created, and exportingProcesses
518  // is updated
519  std::map<AgentId, int>* getRecord(int rank);
520 
521  // Removes the entry for the specified agent.
522  // Returns the number associated with that agent (essentially the number of 'entries' removed)
523  // Also: invokes checkRecord
524  inline int removeAll(const AgentId& id, std::map<AgentId, int>* record, int rank);
525 
526  // Removes a single entry for the specified ID (decrements its count)
527  // If the entry does not exist returns 0, otherwise
528  // returns one (representing one entry removed)
529  // Also: invokes checkRecord
530  inline int removeID(const AgentId& id, std::map<AgentId, int>* record, int rank);
531 
532  // Removes the entire entry for a given agent, by position. Does not return
533  // any indication of success of operation
534  // Invokes checkRecord
535  inline void removeID(std::map<AgentId, int>::iterator idPosition, std::map<AgentId, int>* record, int rank);
536 
537  // Checks if the record size is zero; if so, deletes it and notifies exportingProcesses
538  inline void checkRecord(std::map<AgentId, int>* record, int rank);
539 
540 
541 public:
543  ~Importer_MAP_int();
544 
545  virtual void registerOutgoingRequests(AgentRequest& req);
546  virtual void importedAgentIsRemoved(const AgentId& id);
547  virtual void importedAgentIsMoved(const AgentId& id, int newProcess);
548 
549  virtual std::string getReport();
550  virtual void getSetOfAgentsBeingImported(std::set<AgentId>& set);
551 
552  virtual void clear(){
553  AbstractImporter::clear();
554  sources.clear();
555  }
556 };
557 #endif
558 
559 
560 
561 
562 
563 
564 
565 
566 
567 
568 /* Exporters */
569 
570 static std::vector<AgentStatus> emptyStatus;
571 
584 public:
585  typedef std::map<int, std::set<AgentStatus> > StatusMap;
586 
587 private:
588  StatusMap* outgoingStatusChangesDeletePtr;
589  AgentExporterData* outgoingAgentExporterInformationDeletePtr;
590 
591 protected:
592  StatusMap* outgoingStatusChanges;
593  AgentExporterData* outgoingAgentExporterInformation;
594 
595  std::set<int> processesExportedTo;
596  std::map<int, AgentRequest> exportedMap;
597 
598 public:
599 
601  virtual ~AbstractExporter();
602 
607  virtual void registerIncomingRequests(std::vector<AgentRequest>& requests) = 0;
608 
616  virtual void incorporateAgentExporterInfo(std::map<int, AgentRequest*> info);
617 
618 
627  virtual void agentRemoved(const AgentId& id);
628 
639  virtual void agentMoved(const AgentId& id, int process);
640 
645  virtual const std::set<int>& getProcessesExportedTo();
646 
652  AgentExporterInfo* getAgentExportInfo(int destProc);
653 
657  const StatusMap* getOutgoingStatusChanges();
658 
663  void clearAgentExportInfo();
664 
669  void clearStatusMap();
670 
676  virtual const std::map<int, AgentRequest>& getAgentsToExport();
677 
678 #ifdef SHARE_AGENTS_BY_SET
679 public:
680  AbstractExporter(StatusMap* outgoingStatusMap, AgentExporterData* outgoingAgentExporterInfo);
681 #endif
682 
686  virtual std::string getReport() = 0;
687 
688  virtual void clear(){
689  outgoingStatusChanges->clear();
690  outgoingAgentExporterInformation->clear();
691 
692  processesExportedTo.clear();
693  exportedMap.clear();
694  }
695 
696  virtual void clearExportToSpecificProc(int rank){
697  processesExportedTo.erase(rank);
698  exportedMap.erase(rank);
699  }
700 
701 };
702 
703 
704 #if !defined OMIT_IMPORTER_EXPORTER_COUNT_LIST || \
705  !defined OMIT_IMPORTER_EXPORTER_LIST || \
706  !defined OMIT_IMPORTER_EXPORTER_SET || \
707  !defined OMIT_IMPORTER_EXPORTER_MAP_int
708 
718 private:
719 
720 public:
721  Exporter_LIST();
722  virtual ~Exporter_LIST();
723 
724  virtual void registerIncomingRequests(std::vector<AgentRequest>& requests);
725 
726 #ifdef SHARE_AGENTS_BY_SET
727 public:
728  Exporter_LIST(StatusMap* outgoingStatusMap, AgentExporterData* outgoingAgentExporterInfo);
729 #endif
730 
731  virtual std::string getReport();
732 };
733 #endif
734 
735 
736 #ifndef OMIT_IMPORTER_EXPORTER_COUNT_SET
737 
747 
748 public:
749  Exporter_SET();
750  virtual ~Exporter_SET();
751 
752  virtual void registerIncomingRequests(std::vector<AgentRequest>& requests);
753 
754 #ifdef SHARE_AGENTS_BY_SET
755 public:
756  Exporter_SET(StatusMap* outgoingStatusMap, AgentExporterData* outgoingAgentExporterInfo);
757 #endif
758 
759  virtual std::string getReport();
760 };
761 #endif
762 
763 
764 /* Importer and Exporter */
765 
773 
774 protected:
775  AbstractImporter* importer;
776  AbstractExporter* exporter;
777 
778 public:
780  virtual ~AbstractImporterExporter();
781 
782  // Pass-through methods for all importer and exporter public methods
783  virtual const std::set<int>& getExportingProcesses(){ return importer->getExportingProcesses(); }
784  virtual void registerOutgoingRequests(AgentRequest &req){ importer->registerOutgoingRequests(req); }
785  virtual void importedAgentIsRemoved(const AgentId& id){ importer->importedAgentIsRemoved(id); }
786  virtual void importedAgentIsMoved(const AgentId& id, int newProcess){ importer->importedAgentIsMoved(id, newProcess); }
787 
788  virtual void importedAgentIsNowLocal(const AgentId& id){ importer->importedAgentIsNowLocal(id); }
789 
790  virtual void getSetOfAgentsBeingImported(std::set<AgentId>& set){ importer->getSetOfAgentsBeingImported(set); }
791 
792  virtual const AbstractExporter::StatusMap* getOutgoingStatusChanges();
793 
794  virtual const std::set<int>& getProcessesExportedTo(){ return exporter->getProcessesExportedTo(); }
795  virtual void registerIncomingRequests(std::vector<AgentRequest>& requests){ exporter->registerIncomingRequests(requests); }
796  virtual void agentRemoved(const AgentId& id){ exporter->agentRemoved(id); }
797  virtual void agentMoved(const AgentId& id, int process){ exporter->agentMoved(id, process); }
798  virtual void incorporateAgentExporterInfo(std::map<int, AgentRequest* > info){ exporter->incorporateAgentExporterInfo(info); }
799  virtual void clearStatusMap(){ exporter->clearStatusMap(); }
800  virtual AgentExporterInfo* getAgentExportInfo(int destProc){ return exporter->getAgentExportInfo(destProc); }
801  virtual void clearAgentExportInfo(){ exporter->clearAgentExportInfo(); }
802  virtual const std::map<int, AgentRequest>& getAgentsToExport(){ return exporter->getAgentsToExport(); }
803 
809  virtual void exchangeAgentStatusUpdates(boost::mpi::communicator comm, std::vector<std::vector<AgentStatus>* >& statusUpdates);
810 
816  virtual std::string version() = 0;
817 
821  virtual std::string getReport(){ return importer->getReport() + exporter->getReport(); }
822 
823  virtual void clear(){
824  importer->clear();
825  exporter->clear();
826  }
827 
828  virtual void clearExporter(){
829  exporter->clear();
830  }
831 
832  virtual void clearExportToSpecificProc(int rank){
833  exporter->clearExportToSpecificProc(rank);
834  }
835 
836 };
837 
838 /* Normal variants, with semantics defined by which importer/exporter combination is used */
839 
840 #ifndef OMIT_IMPORTER_EXPORTER_COUNT_LIST
841 
848 public:
850 
851 #ifdef SHARE_AGENTS_BY_SET
852  ImporterExporter_COUNT_LIST(AbstractExporter::StatusMap* outgoingStatusMap, AgentExporterData* outgoingAgentExporterInfo);
853 #endif
854 
855  virtual ~ImporterExporter_COUNT_LIST();
856 
857  virtual std::string version();
858 
859 };
860 #endif
861 
862 #ifndef OMIT_IMPORTER_EXPORTER_COUNT_SET
863 
869 public:
871 
872 #ifdef SHARE_AGENTS_BY_SET
873  ImporterExporter_COUNT_SET(AbstractExporter::StatusMap* outgoingStatusMap, AgentExporterData* outgoingAgentExporterInfo);
874 #endif
875 
876  virtual ~ImporterExporter_COUNT_SET();
877 
878  virtual std::string version();
879 };
880 #endif
881 
882 #ifndef OMIT_IMPORTER_EXPORTER_LIST
883 
890 public:
892 
893 #ifdef SHARE_AGENTS_BY_SET
894  ImporterExporter_LIST(AbstractExporter::StatusMap* outgoingStatusMap, AgentExporterData* outgoingAgentExporterInfo);
895 #endif
896 
897  virtual ~ImporterExporter_LIST();
898 
899  virtual std::string version();
900 };
901 #endif
902 
903 #ifndef OMIT_IMPORTER_EXPORTER_SET
904 
910 public:
912 
913 #ifdef SHARE_AGENTS_BY_SET
914  ImporterExporter_SET(AbstractExporter::StatusMap* outgoingStatusMap, AgentExporterData* outgoingAgentExporterInfo);
915 #endif
916 
917  virtual ~ImporterExporter_SET();
918 
919  virtual std::string version();
920 };
921 #endif
922 
923 #ifndef OMIT_IMPORTER_EXPORTER_MAP_int
924 
930 public:
932 
933 #ifdef SHARE_AGENTS_BY_SET
934  ImporterExporter_MAP_int(AbstractExporter::StatusMap* outgoingStatusMap, AgentExporterData* outgoingAgentExporterInfo);
935 #endif
936 
937  virtual ~ImporterExporter_MAP_int();
938 
939  virtual std::string version();
940 };
941 #endif
942 
943 
944 /* "BY SET" variant; allows multiple sets of shared agents to be managed independently */
945 
946 #ifdef SHARE_AGENTS_BY_SET
947 
957 
958 private:
959 
960  AbstractExporter::StatusMap* outgoingStatusChanges;
961  AgentExporterData* outgoingAgentExporterInformation;
962  std::map<std::string, AbstractImporterExporter*> importersExportersMap;
963  std::set<int> exportingProcesses;
964  bool exportingProcessesIsDirty;
965  std::set<int> processesExportedTo;
966  bool processesExportedToIsDirty;
967  std::map<int, AgentRequest> exportedMap;
968  bool exportedMapIsDirty;
969 
970  AbstractImporterExporter* getSet(std::string setname,
971  AGENT_IMPORTER_EXPORTER_TYPE setType = DEFAULT_ENUM_SYMBOL);
972 
973 
974  inline void rebuildExportingProcesses(bool forceRebuild = false);
975 
976  inline void rebuildProcessesExportedTo(bool forceRebuild = false);
977 
978  inline void rebuildExportedMap(bool forceRebuild = false);
979 
980 public:
982 
983  virtual ~ImporterExporter_BY_SET();
984 
985 
986  /* Importer-related functions */
987 
988  virtual const std::set<int>& getExportingProcesses();
989  const std::set<int>& getExportingProcesses(std::string setName);
990 
991 
992  virtual void registerOutgoingRequests(AgentRequest& request);
993  void registerOutgoingRequests(AgentRequest& request, std::string setName,
994  AGENT_IMPORTER_EXPORTER_TYPE setType = DEFAULT_ENUM_SYMBOL);
995 
996  virtual void importedAgentIsRemoved(const AgentId& id);
997 
998  virtual void importedAgentIsMoved(const AgentId& id, int newProcess);
999 
1000  virtual void importedAgentIsNowLocal(const AgentId& id);
1001 
1002 
1003  /* Exporter-related functions */
1004 
1005  virtual const AbstractExporter::StatusMap* getOutgoingStatusChanges();
1006 
1007  virtual const std::set<int>& getProcessesExportedTo();
1008  const std::set<int>& getProcessesExportedTo(std::string setName);
1009 
1010  virtual void registerIncomingRequests(std::vector<AgentRequest>& requests);
1011  void registerIncomingRequests(std::vector<AgentRequest>& requests, std::string setName);
1012 
1013  virtual void agentRemoved(const AgentId& id);
1014  virtual void agentMoved(const AgentId& id, int newProcess);
1015 
1016  // This should NEVER be called; it is inappropriate to use this when 'by set' is being used
1017  virtual void incorporateAgentExporterInfo(std::map<int, AgentRequest* > info);
1018  void incorporateAgentExporterInfo(std::map<std::string, std::map<int, AgentRequest*>*> info);
1019 
1020  virtual void clearStatusMap();
1021 
1022  virtual AgentExporterInfo* getAgentExportInfo(int destProc);
1023 
1024  virtual void clearAgentExportInfo();
1025 
1026  virtual const std::map<int, AgentRequest>& getAgentsToExport();
1027  const std::map<int, AgentRequest>& getAgentsToExport(std::string setName);
1028 
1029  virtual std::string version();
1030 
1031  void dropSet(std::string setName){
1032  importersExportersMap.erase(setName); // Fails silently if the specified set is not present
1033  }
1034 
1035  virtual std::string getReport(){
1036  std::stringstream ss;
1037  std::map<std::string, AbstractImporterExporter*>::iterator it = importersExportersMap.begin();
1038  std::map<std::string, AbstractImporterExporter*>::iterator itEnd = importersExportersMap.end();
1039  while(it != itEnd){
1040  ss << it->first << "\n" << it->second->getReport();
1041  it++;
1042  }
1043  return ss.str();
1044  }
1045 
1046  virtual void getSetOfAgentsBeingImported(std::set<AgentId>& set);
1047  void getSetOfAgentsBeingImported(std::set<AgentId>& set, std::string excludeSet);
1048 
1049  virtual void clear(){
1050  std::map<std::string, AbstractImporterExporter*>::iterator it = importersExportersMap.begin();
1051  std::map<std::string, AbstractImporterExporter*>::iterator itEnd = importersExportersMap.end();
1052  while(it != itEnd){
1053  it->second->clear();
1054  it++;
1055  }
1056  }
1057 
1058  void clear(std::string setName){
1059  std::map<std::string, AbstractImporterExporter*>::iterator it = importersExportersMap.find(setName);
1060  if(it != importersExportersMap.end()) it->second->clear();
1061  }
1062 
1063  virtual void clearExporter(){
1064  std::map<std::string, AbstractImporterExporter*>::iterator it = importersExportersMap.begin();
1065  std::map<std::string, AbstractImporterExporter*>::iterator itEnd = importersExportersMap.end();
1066  while(it != itEnd){
1067  it->second->clearExporter();
1068  it++;
1069  }
1070  }
1071 
1072  void clearExporter(std::string setName){
1073  std::map<std::string, AbstractImporterExporter*>::iterator it = importersExportersMap.find(setName);
1074  if(it != importersExportersMap.end()) it->second->clearExporter();
1075  }
1076 
1077  void clearExportToSpecificProc(int rank){
1078  std::map<std::string, AbstractImporterExporter*>::iterator it = importersExportersMap.begin();
1079  std::map<std::string, AbstractImporterExporter*>::iterator itEnd = importersExportersMap.end();
1080  while(it != itEnd){
1081  it->second->clearExportToSpecificProc(rank);
1082  it++;
1083  }
1084  }
1085 
1086 };
1087 #endif
1088 
1089 }
1090 #endif /* AGENTIMPORTEREXPORTER_H_ */
repast::ImporterExporter_LIST
An implementation of AbstractImporterExporter that uses an importer of type 'Importer_LIST' and an ex...
Definition: AgentImporterExporter.h:889
repast::Importer_COUNT
Importer that maintains a simple count of the agents being sent from each sending process.
Definition: AgentImporterExporter.h:364
repast::ImporterExporter_COUNT_LIST
An implementation of AbstractImporterExporter that uses an importer of type 'Importer_COUNT' and an e...
Definition: AgentImporterExporter.h:847
repast::Importer_SET::importedAgentIsMoved
virtual void importedAgentIsMoved(const AgentId &id, int newProcess)
Notifies this importer that the agent that it (presumably) has been importing from another process ha...
Definition: AgentImporterExporter.cpp:515
repast::Importer_MAP_int::getReport
virtual std::string getReport()
Get a printable indication of the data in this object.
Definition: AgentImporterExporter.cpp:709
repast::AbstractImporter::registerOutgoingRequests
virtual void registerOutgoingRequests(AgentRequest &req)=0
Given an agent request (including requests for agents on multiple other processes),...
repast::AbstractExporter::getOutgoingStatusChanges
const StatusMap * getOutgoingStatusChanges()
Gets the set of status changes for the exported agents.
Definition: AgentImporterExporter.cpp:850
repast::ImporterExporter_BY_SET
Implementation of the AbstractImporterExporter class that wraps a collection of AbstractImporterExpor...
Definition: AgentImporterExporter.h:956
repast::ImporterExporter_BY_SET::getReport
virtual std::string getReport()
Gets a printable report of the state of this object.
Definition: AgentImporterExporter.h:1035
repast::AbstractExporter::getProcessesExportedTo
virtual const std::set< int > & getProcessesExportedTo()
Gets the list of processes this exporter is sending information to.
Definition: AgentImporterExporter.cpp:780
repast::AbstractExporter::clearAgentExportInfo
void clearAgentExportInfo()
Clears the outgoing agent export information buffer; should be called after the information is sent.
Definition: AgentImporterExporter.cpp:854
repast::Importer_LIST::getReport
virtual std::string getReport()
Get a printable indication of the data in this object.
Definition: AgentImporterExporter.cpp:408
repast::AgentId
Agent identity information.
Definition: AgentId.h:60
repast::ImporterExporter_COUNT_SET::version
virtual std::string version()
Returns the version of this AbstractImporterExporter.
Definition: AgentImporterExporter.cpp:1082
repast::Importer_COUNT::importedAgentIsMoved
virtual void importedAgentIsMoved(const AgentId &id, int newProcess)
Notifies this importer that the agent that it (presumably) has been importing from another process ha...
Definition: AgentImporterExporter.cpp:240
repast::Importer_MAP_int
Importer that maintains a map of agents being sent from each sending process and a count of the numbe...
Definition: AgentImporterExporter.h:510
repast::Importer_COUNT::getReport
virtual std::string getReport()
Get a printable indication of the data in this object.
Definition: AgentImporterExporter.cpp:245
repast::Importer_MAP_int::importedAgentIsRemoved
virtual void importedAgentIsRemoved(const AgentId &id)
Notifies this importer that the agent that it (presumably) has been importing has been removed from t...
Definition: AgentImporterExporter.cpp:693
repast::AgentExporterData::selectSet
void selectSet(std::string setName)
Specifies that add and retrieve actions are to be performed on the subset of data identified by the g...
Definition: AgentImporterExporter.cpp:183
repast::AgentExporterData::removeAllDataForAgent
void removeAllDataForAgent(AgentId &id)
Remove all the data for a specific agent; useful when the agent is removed.
Definition: AgentImporterExporter.cpp:155
repast::AbstractImporter::getReport
virtual std::string getReport()=0
Get a printable indication of the data in this object.
repast::Importer_MAP_int::importedAgentIsMoved
virtual void importedAgentIsMoved(const AgentId &id, int newProcess)
Notifies this importer that the agent that it (presumably) has been importing from another process ha...
Definition: AgentImporterExporter.cpp:698
repast::AbstractExporter::agentRemoved
virtual void agentRemoved(const AgentId &id)
1) Removes the agent export information from this process 2) Updates the outgoing status change buffe...
Definition: AgentImporterExporter.cpp:785
repast::AbstractImporterExporter::exchangeAgentStatusUpdates
virtual void exchangeAgentStatusUpdates(boost::mpi::communicator comm, std::vector< std::vector< AgentStatus > * > &statusUpdates)
Exchanges the contents of the 'statusMap' with the destination processes, updating the status (moved ...
Definition: AgentImporterExporter.cpp:1008
repast::Exporter_SET::getReport
virtual std::string getReport()
Gets a printable report of the state of this object.
Definition: AgentImporterExporter.cpp:980
repast::AgentExporterData::dataForProc
AgentExporterInfo * dataForProc(int destProc)
Gets the packaged set of information to be sent to a specific processor.
Definition: AgentImporterExporter.cpp:119
repast::Importer_SET::getReport
virtual std::string getReport()
Get a printable indication of the data in this object.
Definition: AgentImporterExporter.cpp:528
repast::AbstractExporter::agentMoved
virtual void agentMoved(const AgentId &id, int process)
1) Removes the agent export information from this process 2) Places a copy of the agent export inform...
Definition: AgentImporterExporter.cpp:809
repast::AbstractImporter::importedAgentIsMoved
virtual void importedAgentIsMoved(const AgentId &id, int newProcess)=0
Notifies this importer that the agent that it (presumably) has been importing from another process ha...
repast::Importer_SET::importedAgentIsRemoved
virtual void importedAgentIsRemoved(const AgentId &id)
Notifies this importer that the agent that it (presumably) has been importing has been removed from t...
Definition: AgentImporterExporter.cpp:510
repast::ImporterExporter_MAP_int::version
virtual std::string version()
Returns the version of this AbstractImporterExporter.
Definition: AgentImporterExporter.cpp:1124
repast::AgentExporterData::addData
void addData(const AgentId &id, const int destProc, const int sourceProc, const int numberOfCopies=1)
Adds an agent ID to this list of data that is being exported to a specific processor (destProc),...
Definition: AgentImporterExporter.cpp:63
repast::Exporter_LIST::getReport
virtual std::string getReport()
Gets a printable report of the state of this object.
Definition: AgentImporterExporter.cpp:915
repast::Exporter_LIST::registerIncomingRequests
virtual void registerIncomingRequests(std::vector< AgentRequest > &requests)
Makes a record of the data receives (in the form of a vector of AgentRequests) so that the agents' da...
Definition: AgentImporterExporter.cpp:883
repast::Importer_SET
Importer that maintains a set of agents being sent from each sending process.
Definition: AgentImporterExporter.h:458
repast::Exporter_SET
Maintains a set of agents being exported for each receiving process.
Definition: AgentImporterExporter.h:746
repast::ImporterExporter_COUNT_LIST::version
virtual std::string version()
Returns the version of this AbstractImporterExporter.
Definition: AgentImporterExporter.cpp:1068
repast::AbstractExporter::getReport
virtual std::string getReport()=0
Gets a printable report of the state of this object.
repast::AbstractImporter::importedAgentIsRemoved
virtual void importedAgentIsRemoved(const AgentId &id)=0
Notifies this importer that the agent that it (presumably) has been importing has been removed from t...
repast::AbstractExporter
Responsible for keeping a list of the agents that have been requested by other processes for which da...
Definition: AgentImporterExporter.h:583
repast::AbstractImporter
This class manages importing agent information; primarily this means constructing the appropriate mpi...
Definition: AgentImporterExporter.h:295
repast::Importer_LIST::registerOutgoingRequests
virtual void registerOutgoingRequests(AgentRequest &req)
Given an agent request (including requests for agents on multiple other processes),...
Definition: AgentImporterExporter.cpp:318
repast::AgentRequest
Encapsulates a request made by one process for agents in another.
Definition: AgentRequest.h:59
repast::Importer_LIST
Importer that maintains a list of the agents being sent from each sending process.
Definition: AgentImporterExporter.h:400
repast::AgentExporterData
Data structure for exporter data that is to be sent to other processes when the agents being exported...
Definition: AgentImporterExporter.h:199
repast::Importer_MAP_int::registerOutgoingRequests
virtual void registerOutgoingRequests(AgentRequest &req)
Given an agent request (including requests for agents on multiple other processes),...
Definition: AgentImporterExporter.cpp:625
repast::Exporter_SET::registerIncomingRequests
virtual void registerIncomingRequests(std::vector< AgentRequest > &requests)
Makes a record of the data receives (in the form of a vector of AgentRequests) so that the agents' da...
Definition: AgentImporterExporter.cpp:943
repast::Importer_LIST::importedAgentIsRemoved
virtual void importedAgentIsRemoved(const AgentId &id)
Notifies this importer that the agent that it (presumably) has been importing has been removed from t...
Definition: AgentImporterExporter.cpp:391
repast::Importer_SET::registerOutgoingRequests
virtual void registerOutgoingRequests(AgentRequest &req)
Given an agent request (including requests for agents on multiple other processes),...
Definition: AgentImporterExporter.cpp:486
repast::AbstractExporter::incorporateAgentExporterInfo
virtual void incorporateAgentExporterInfo(std::map< int, AgentRequest * > info)
The set of information received here comprises the information that some other process was using to e...
Definition: AgentImporterExporter.cpp:836
repast::AbstractExporter::clearStatusMap
void clearStatusMap()
Clears the outgoing status information buffer; should be called after the information is sent.
Definition: AgentImporterExporter.cpp:858
repast::AbstractExporter::getAgentExportInfo
AgentExporterInfo * getAgentExportInfo(int destProc)
Gets the export information that has been placed into the 'outgoing agent export information' buffer ...
Definition: AgentImporterExporter.cpp:846
repast::AbstractImporter::getExportingProcesses
virtual const std::set< int > & getExportingProcesses()
Gets a const reference to the set of ints representing the processes that are sending this process ag...
Definition: AgentImporterExporter.h:309
repast::AbstractExporter::registerIncomingRequests
virtual void registerIncomingRequests(std::vector< AgentRequest > &requests)=0
Makes a record of the data receives (in the form of a vector of AgentRequests) so that the agents' da...
repast::Exporter_LIST
Maintains a list of agents being exported for each receiving process.
Definition: AgentImporterExporter.h:717
repast::AbstractImporterExporter::getReport
virtual std::string getReport()
Gets a printable report of the state of this object.
Definition: AgentImporterExporter.h:821
repast::Importer_COUNT::importedAgentIsRemoved
virtual void importedAgentIsRemoved(const AgentId &id)
Notifies this importer that the agent that it (presumably) has been importing has been removed from t...
Definition: AgentImporterExporter.cpp:236
repast::Importer_COUNT::registerOutgoingRequests
virtual void registerOutgoingRequests(AgentRequest &req)
Given an agent request (including requests for agents on multiple other processes),...
Definition: AgentImporterExporter.cpp:230
repast::ImporterExporter_MAP_int
An implementation of AbstractImporterExporter that uses an importer of type 'Importer_MAP_int' and an...
Definition: AgentImporterExporter.h:929
repast::AbstractImporterExporter
Wraps and Importer and an Exporter so that both use commensurate semantics and all imports and export...
Definition: AgentImporterExporter.h:772
repast::ImporterExporter_SET
An implementation of AbstractImporterExporter that uses an importer of type 'Importer_SET' and an exp...
Definition: AgentImporterExporter.h:909
repast::ImporterExporter_LIST::version
virtual std::string version()
Returns the version of this AbstractImporterExporter.
Definition: AgentImporterExporter.cpp:1096
repast::ImporterExporter_COUNT_SET
An implementation of AbstractImporterExporter that uses an importer of type 'Importer_COUNT' and an e...
Definition: AgentImporterExporter.h:868
repast::ImporterExporter_SET::version
virtual std::string version()
Returns the version of this AbstractImporterExporter.
Definition: AgentImporterExporter.cpp:1110
repast::ImporterExporter_BY_SET::version
virtual std::string version()
Returns the version of this AbstractImporterExporter.
Definition: AgentImporterExporter.cpp:1410
repast::Importer_LIST::importedAgentIsMoved
virtual void importedAgentIsMoved(const AgentId &id, int newProcess)
Notifies this importer that the agent that it (presumably) has been importing from another process ha...
Definition: AgentImporterExporter.cpp:396
repast::AbstractImporter::importedAgentIsNowLocal
void importedAgentIsNowLocal(const AgentId &id)
Some semantic sugar; operationally this is the same as 'importedAgentIsRemoved'.
Definition: AgentImporterExporter.h:338
repast::AbstractImporterExporter::version
virtual std::string version()=0
Returns the version of this AbstractImporterExporter.
repast::AbstractExporter::getAgentsToExport
virtual const std::map< int, AgentRequest > & getAgentsToExport()
Gets the list of agents being exported by this exported, as a map by ints representing the processes ...
Definition: AgentImporterExporter.cpp:862
repast::AgentExporterData::clear
void clear()
Clears this data structure.
Definition: AgentImporterExporter.cpp:125