├── GroupBy.cuh ├── License.txt ├── Makefile ├── allocator.cuh ├── bfs_gpu_opt.cuh ├── comm.h ├── expander.cu ├── expander.cuh ├── gen_script.bash ├── get_time.bash ├── gpu_ibfs.cu ├── gpu_ibfs.cuh ├── graph.cu ├── graph.cuh ├── graph.h ├── graph_reader.cuh ├── graph_reader.h ├── groupby.cu ├── ibfs.cu ├── ibfs.h ├── inspector.cu ├── inspector.cuh ├── launch.bash ├── main.cpp ├── main.cu ├── proc_profil.bash ├── proc_time.bash ├── readme.md ├── reporter.cpp ├── run.bash ├── scan.cuh ├── traversal.cu ├── tuple_text_to_binary_csr ├── Makefile └── tuple_text_to_bin.cpp ├── util.h ├── validate.h ├── write_result.cuh └── wtime.h /GroupBy.cuh: -------------------------------------------------------------------------------- 1 | #ifndef __GROUPBY__ 2 | #define __GROUPBY__ 3 | 4 | #include "comm.h" 5 | 6 | template 7 | int GroupBy( 8 | index_t num_bfs, 9 | vertex_t *source_list, 10 | vertex_t *new_list, 11 | csr_graph ggraph 12 | ){ 13 | index_t *hubmap=new index_t[ggraph->vert_count]; 14 | index_t *huboff=new index_t[ggraph->vert_count]; 15 | memset(hubmap,0,sizeof(index_t)*ggraph->vert_count); 16 | memset(huboff,0,sizeof(index_t)*ggraph->vert_count); 17 | 18 | /*counting eligible instances*/ 19 | for(index_t i=0;ibeg_pos[source_list[i]]; 22 | index_t end=ggraph->beg_pos[source_list[i]+1]; 23 | 24 | /*out-degree <= sdegree*/ 25 | if(end-beg>128) continue; 26 | 27 | for(index_t j=beg;jbeg_pos[ggraph->adj_list[j]+1]- 31 | ggraph->beg_pos[ggraph->adj_list[j]] > 128) 32 | { 33 | hubmap[ggraph->adj_list[j]]++; 34 | break; 35 | } 36 | } 37 | } 38 | 39 | /*prefix-sum counted data*/ 40 | huboff[0]=0; 41 | for(index_t i=1;ivert_count;i++) 42 | huboff[i]=huboff[i-1]+hubmap[i-1]; 43 | index_t remainoff=huboff[ggraph->vert_count-1]+hubmap[ggraph->vert_count-1]; 44 | 45 | 46 | index_t test=0; 47 | /*formulating group*/ 48 | for(index_t i=0;ibeg_pos[source_list[i]]; 51 | index_t end=ggraph->beg_pos[source_list[i]+1]; 52 | 53 | /*non-eligible instance*/ 54 | if(end-beg>128) 55 | { 56 | new_list[remainoff]=source_list[i]; 57 | remainoff++; 58 | test++; 59 | continue; 60 | 61 | } 62 | 63 | /*eligible instance*/ 64 | bool isEligible=false; 65 | for(index_t j=beg;jbeg_pos[ggraph->adj_list[j]+1]- 69 | ggraph->beg_pos[ggraph->adj_list[j]] > 128) 70 | { 71 | new_list[huboff[ggraph->adj_list[j]]]=source_list[i]; 72 | huboff[ggraph->adj_list[j]]++; 73 | isEligible=true; 74 | break; 75 | } 76 | } 77 | 78 | if(!isEligible) 79 | { 80 | new_list[remainoff]=source_list[i]; 81 | remainoff++; 82 | test++; 83 | } 84 | } 85 | 86 | std::ofstream myfile("origin_source.dat"); 87 | std::ofstream newfile("new_source.dat"); 88 | for(index_t i=0;ivert_count;i++) 101 | { 102 | if(hubmap[i]) 103 | { 104 | std::cout< 6 | 7 | Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The GNU General Public License is a free, copyleft license for software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. 14 | 15 | When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. 16 | 17 | To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. 18 | 19 | For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. 20 | 21 | Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. 22 | 23 | For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. 24 | 25 | Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. 26 | 27 | Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. 28 | 29 | The precise terms and conditions for copying, distribution and modification follow. 30 | 31 | TERMS AND CONDITIONS 32 | 33 | 0. Definitions. 34 | 35 | “This License” refers to version 3 of the GNU General Public License. 36 | 37 | “Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. 38 | 39 | “The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations. 40 | 41 | To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work. 42 | 43 | A “covered work” means either the unmodified Program or a work based on the Program. 44 | 45 | To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. 46 | 47 | To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. 48 | 49 | An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 50 | 51 | 1. Source Code. 52 | 53 | The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work. 54 | 55 | A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. 56 | 57 | The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. 58 | 59 | The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. 60 | 61 | The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. 62 | 63 | The Corresponding Source for a work in source code form is that same work. 64 | 65 | 2. Basic Permissions. 66 | 67 | All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. 68 | 69 | You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. 70 | 71 | Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 72 | 73 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 74 | 75 | No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. 76 | 77 | When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 78 | 79 | 4. Conveying Verbatim Copies. 80 | 81 | You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. 82 | 83 | You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 84 | 85 | 5. Conveying Modified Source Versions. 86 | 87 | You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: 88 | 89 | a) The work must carry prominent notices stating that you modified it, and giving a relevant date. 90 | b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”. 91 | c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. 92 | d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. 93 | A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 94 | 95 | 6. Conveying Non-Source Forms. 96 | 97 | You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: 98 | 99 | a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. 100 | b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. 101 | c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. 102 | d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. 103 | e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. 104 | A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. 105 | 106 | A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. 107 | 108 | “Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. 109 | 110 | If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). 111 | 112 | The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. 113 | 114 | Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 115 | 116 | 7. Additional Terms. 117 | 118 | “Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. 119 | 120 | When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. 121 | 122 | Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: 123 | 124 | a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or 125 | b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or 126 | c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or 127 | d) Limiting the use for publicity purposes of names of licensors or authors of the material; or 128 | e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or 129 | f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. 130 | All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. 131 | 132 | If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. 133 | 134 | Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 135 | 136 | 8. Termination. 137 | 138 | You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). 139 | 140 | However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. 141 | 142 | Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. 143 | 144 | Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 145 | 146 | 9. Acceptance Not Required for Having Copies. 147 | 148 | You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 149 | 150 | 10. Automatic Licensing of Downstream Recipients. 151 | 152 | Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. 153 | 154 | An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. 155 | 156 | You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 157 | 158 | 11. Patents. 159 | 160 | A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”. 161 | 162 | A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. 163 | 164 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. 165 | 166 | In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. 167 | 168 | If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. 169 | 170 | If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. 171 | 172 | A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. 173 | 174 | Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 175 | 176 | 12. No Surrender of Others' Freedom. 177 | 178 | If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 179 | 180 | 13. Use with the GNU Affero General Public License. 181 | 182 | Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 183 | 184 | 14. Revised Versions of this License. 185 | 186 | The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. 187 | 188 | Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. 189 | 190 | If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. 191 | 192 | Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 193 | 194 | 15. Disclaimer of Warranty. 195 | 196 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 197 | 198 | 16. Limitation of Liability. 199 | 200 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 201 | 202 | 17. Interpretation of Sections 15 and 16. 203 | 204 | If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. 205 | 206 | END OF TERMS AND CONDITIONS 207 | 208 | How to Apply These Terms to Your New Programs 209 | 210 | If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. 211 | 212 | To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found. 213 | 214 | 215 | Copyright (C) 216 | 217 | This program is free software: you can redistribute it and/or modify 218 | it under the terms of the GNU General Public License as published by 219 | the Free Software Foundation, either version 3 of the License, or 220 | (at your option) any later version. 221 | 222 | This program is distributed in the hope that it will be useful, 223 | but WITHOUT ANY WARRANTY; without even the implied warranty of 224 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 225 | GNU General Public License for more details. 226 | 227 | You should have received a copy of the GNU General Public License 228 | along with this program. If not, see . 229 | Also add information on how to contact you by electronic and paper mail. 230 | 231 | If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: 232 | 233 | Copyright (C) 234 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 235 | This is free software, and you are welcome to redistribute it 236 | under certain conditions; type `show c' for details. 237 | The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”. 238 | 239 | You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . 240 | 241 | The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . 242 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | EXE=gpu-ibfs 2 | 3 | COMMFLAGS=-O3 --compiler-options -Wall -Xptxas -v 4 | CUCC= "$(shell which nvcc)" 5 | 6 | CUFLAGS= -arch=sm_35 ${COMMFLAGS}#-Xptxas -dlcm=cg#disable l1 cache 7 | CUFLAGS+= -ccbin=g++ -Xcompiler -fopenmp 8 | 9 | 10 | MPC = "$(shell which mpicxx)" 11 | MPCFLAGS = -Wall -I"$(shell dirname $(CUCC))/../include" -L"$(shell dirname $(CUCC))/../lib64" -lcudart -fopenmp 12 | 13 | 14 | ifeq ($(enable_monitor), 1) 15 | CUFLAGS+= -DENABLE_MONITORING 16 | endif 17 | 18 | ifeq ($(enable_check), 1) 19 | CUFLAGS+= -DENABLE_CHECKING 20 | endif 21 | 22 | 23 | ifeq ($(enable_groupby), 1) 24 | CUFLAGS+= -DGROUPBY 25 | endif 26 | 27 | 28 | OBJS= main.o \ 29 | ibfs.o \ 30 | reporter.o 31 | 32 | DEPS= Makefile \ 33 | expander.cuh \ 34 | inspector.cuh \ 35 | comm.h \ 36 | graph.cuh \ 37 | bfs_gpu_opt.cuh \ 38 | wtime.h \ 39 | validate.h \ 40 | scan.cuh \ 41 | allocator.cuh 42 | 43 | %.o:%.cpp $(DEPS) 44 | ${MPC} -c ${MPCFLAGS} $< -o $@ 45 | 46 | %.o:%.cu $(DEPS) 47 | ${CUCC} -c ${CUFLAGS} $< -o $@ 48 | 49 | ${EXE}:${OBJS} 50 | ${MPC} ${OBJS} $(MPCFLAGS) -o ${EXE} 51 | 52 | clean: 53 | rm -rf *.o ${EXE} 54 | -------------------------------------------------------------------------------- /allocator.cuh: -------------------------------------------------------------------------------- 1 | #include "comm.h" 2 | 3 | template 4 | int graph::alloc_array() 5 | { 6 | cudaSetDevice(gpu_id); 7 | //long cpu_bytes= 0; 8 | long gpu_bytes= 0; 9 | 10 | const size_t cat_index_sz = sizeof(index_t)*BLKS_NUM*THDS_NUM; 11 | //const size_t blk_sz = sizeof(index_t)*BLKS_NUM*num_agg_bfs; 12 | const size_t merge_depth_sz = sizeof(depth_t)*vert_count*num_agg_bfs; 13 | const size_t edge_sz = sizeof(vertex_t)*edge_count; 14 | const size_t vert_sz = sizeof(vertex_t)*vert_count; 15 | const size_t index_sz = sizeof(index_t)*vert_count; 16 | const size_t comp_sz = sizeof(comp_t)*vert_count; 17 | const size_t src_sz = sizeof(vertex_t)*src_count; 18 | gpu_bytes+= edge_sz+(index_sz*2); 19 | gpu_bytes+=(cat_index_sz*6); 20 | gpu_bytes+=(comp_sz*2)+src_sz+merge_depth_sz; 21 | gpu_bytes+=(vert_sz*3); 22 | std::cout<<"GPU space: "<edge_count=edge_count; 25 | ggraph->vert_count=vert_count; 26 | // H_ERR(cudaSetDeviceFlags(cudaDeviceMapHost)); 27 | H_ERR(cudaMalloc((void **)&ggraph->adj_card_d, index_sz)); 28 | H_ERR(cudaMalloc((void **)&ggraph->beg_pos_d, index_sz)); 29 | H_ERR(cudaMalloc((void **)&ggraph->adj_list_d, edge_sz)); 30 | H_ERR(cudaMalloc((void **)&ggraph->depth_merge, merge_depth_sz)); 31 | H_ERR(cudaMemcpy(ggraph->beg_pos_d,ggraph->beg_pos,index_sz, 32 | cudaMemcpyHostToDevice)); 33 | H_ERR(cudaMemcpy(ggraph->adj_card_d,ggraph->adj_card,index_sz, 34 | cudaMemcpyHostToDevice)); 35 | H_ERR(cudaMemcpy(ggraph->adj_list_d,ggraph->adj_list,edge_sz, 36 | cudaMemcpyHostToDevice)); 37 | 38 | H_ERR(cudaMalloc((void **)&ggraph->ex_sml_off, cat_index_sz)); 39 | H_ERR(cudaMalloc((void **)&ggraph->ex_mid_off, cat_index_sz)); 40 | H_ERR(cudaMalloc((void **)&ggraph->ex_lrg_off, cat_index_sz)); 41 | H_ERR(cudaMalloc((void **)&ggraph->ex_cat_sml_sz, cat_index_sz)); 42 | H_ERR(cudaMalloc((void **)&ggraph->ex_cat_mid_sz, cat_index_sz)); 43 | H_ERR(cudaMalloc((void **)&ggraph->ex_cat_lrg_sz, cat_index_sz)); 44 | 45 | H_ERR(cudaMalloc((void **)&ggraph->ex_sml_q, vert_sz)); 46 | H_ERR(cudaMalloc((void **)&ggraph->ex_mid_q, vert_sz)); 47 | H_ERR(cudaMalloc((void **)&ggraph->ex_lrg_q, vert_sz)); 48 | 49 | H_ERR(cudaMalloc((void **)&ggraph->src_list,src_sz)); 50 | H_ERR(cudaMemcpy(ggraph->src_list,src_list,src_sz,cudaMemcpyHostToDevice)); 51 | H_ERR(cudaMalloc((void **)&ggraph->depth_comp_last,comp_sz)); 52 | H_ERR(cudaMalloc((void **)&ggraph->depth_comp_curr,comp_sz)); 53 | cudaStreamCreate(&ggraph->gstream); 54 | 55 | for(index_t i=0;iex_sml_sz,sizeof(index_t))); 60 | // H_ERR(cudaMallocHost((void **)&gdata[i]->ex_mid_sz,sizeof(index_t))); 61 | // H_ERR(cudaMallocHost((void **)&gdata[i]->ex_lrg_sz,sizeof(index_t))); 62 | H_ERR(cudaHostAlloc((void **)&gdata[i]->ex_sml_sz, 63 | sizeof(index_t),cudaHostAllocMapped)); 64 | H_ERR(cudaHostAlloc((void **)&gdata[i]->ex_mid_sz, 65 | sizeof(index_t),cudaHostAllocMapped)); 66 | H_ERR(cudaHostAlloc((void **)&gdata[i]->ex_lrg_sz, 67 | sizeof(index_t),cudaHostAllocMapped)); 68 | H_ERR(cudaHostGetDevicePointer((void **)&gdata[i]->ex_sml_sz_d, 69 | (void*)gdata[i]->ex_sml_sz,0)); 70 | H_ERR(cudaHostGetDevicePointer((void **)&gdata[i]->ex_mid_sz_d, 71 | (void*)gdata[i]->ex_mid_sz,0)); 72 | H_ERR(cudaHostGetDevicePointer((void **)&gdata[i]->ex_lrg_sz_d, 73 | (void*)gdata[i]->ex_lrg_sz,0)); 74 | 75 | 76 | gdata[i]->stream=(cudaStream_t *)malloc(sizeof(cudaStream_t)*Q_CARD); 77 | for(index_t j=0;jstream[j]); 78 | } 79 | return 0; 80 | } 81 | 82 | -------------------------------------------------------------------------------- /bfs_gpu_opt.cuh: -------------------------------------------------------------------------------- 1 | #include "scan.cuh" 2 | #include "expander.cuh" 3 | #include "inspector.cuh" 4 | #include "wtime.h" 5 | #include "validate.h" 6 | #include "ibfs.h" 7 | 8 | template 9 | bool cont_bfs 10 | ( 11 | index_t level, index_t sw_level, 12 | index_t *qsz, 13 | index_t *last_ct, 14 | index_t num_agg_bfs, 15 | tdata *gdata 16 | ){ 17 | bool cont_traverse=false; 18 | qsz[0]=gdata[0]->ex_sml_sz[0] 19 | +gdata[0]->ex_mid_sz[0] 20 | +gdata[0]->ex_lrg_sz[0]; 21 | 22 | if(!ENABLE_BTUP){ 23 | if(qsz[0]!=0){cont_traverse=true;} 24 | }else{ 25 | if(last_ct[0]!=qsz[0]){ 26 | cont_traverse=true; 27 | last_ct[0]=qsz[0]; 28 | }else if((qsz[0]!=0)&&((level==sw_level+1)||(level==sw_level+2)||(level==sw_level+3)||(level==sw_level+4))){ 29 | cont_traverse=true; 30 | last_ct[0]=qsz[0]; 31 | } 32 | } 33 | // std::cout<<"----\n"; 34 | // std::cout< 40 | void ibfs 41 | ( 42 | vertex_t *src_v, 43 | index_t src_grp_off, 44 | tdata *gdata, 45 | csr_graph ggraph, 46 | index_t num_agg_bfs, 47 | index_t vert_count, 48 | index_t sw_level, 49 | index_t *last_ct, 50 | depth_t &level, 51 | const index_t sml_shed, 52 | const index_t lrg_shed 53 | ) 54 | { 55 | init_bfs 56 | ( 57 | src_v, 58 | src_grp_off, 59 | gdata, 60 | ggraph, 61 | num_agg_bfs, 62 | sml_shed, 63 | lrg_shed 64 | ); 65 | cudaDeviceSynchronize(); 66 | 67 | #ifdef ENABLE_MONITORING 68 | double tm_insp; 69 | double tm_expd; 70 | double tm_step; 71 | double tm_expand = 0.0; 72 | double tm_inspect = 0.0; 73 | // depth_t *d_depth; 74 | // cudaMallocHost((void**)&d_depth,sizeof(depth_t)*vert_count); 75 | // cudaMemcpy(d_depth,ggraph->depth_merge, sizeof(depth_t)*vert_count,cudaMemcpyDeviceToHost); 76 | // for(int i=0;iex_sml_sz[0] 90 | // +gdata[0]->ex_mid_sz[0] 91 | // +gdata[0]->ex_lrg_sz[0]<<" " 92 | // <sw_level+1) 101 | if(!cont_bfs 102 | (level, sw_level, qsz,last_ct,num_agg_bfs,gdata))break; 103 | 104 | //---------------------- 105 | //Expand ex_qs and mark frontier in depth_d 106 | //------------------------------------------------ 107 | #ifdef ENABLE_MONITORING 108 | tm_step=wtime(); 109 | tm_expd=wtime(); 110 | #endif 111 | expander 112 | 113 | ( 114 | gdata, 115 | ggraph, 116 | num_agg_bfs, 117 | sw_level, 118 | level 119 | ); 120 | cudaDeviceSynchronize(); 121 | 122 | #ifdef ENABLE_MONITORING 123 | tm_expd=wtime()-tm_expd; 124 | tm_insp=wtime(); 125 | #endif 126 | //----------------------- 127 | //Generate ex_qs from depth_d 128 | //--------------------------------- 129 | inspector 130 | 131 | ( 132 | gdata, 133 | ggraph, 134 | num_agg_bfs, 135 | sw_level, 136 | level, 137 | vert_count, 138 | sml_shed, 139 | lrg_shed 140 | ); 141 | cudaDeviceSynchronize(); 142 | #ifdef ENABLE_MONITORING 143 | tm_insp=wtime()-tm_insp; 144 | tm_step=wtime()-tm_step; 145 | 146 | std::cout<<"@Level-"<<(int)level; 147 | if(levelex_sml_sz[0] 157 | // +gdata[0]->ex_mid_sz[0] 158 | // +gdata[0]->ex_lrg_sz[0]<<" " 159 | // < 183 | int graph:: 184 | bfs_gpu_coalescing_mem() 185 | { 186 | cudaSetDevice(gpu_id); 187 | depth_t *temp; 188 | // index_t agg_tr_edges, agg_tr_v; 189 | double tm_bfs; 190 | // double average_teps = 0.0; 191 | // double curr_teps = 0.0; 192 | // index_t validate_count = 0; 193 | 194 | cudaMallocHost((void **)&temp,sizeof(depth_t)*vert_count*num_agg_bfs); 195 | for(index_t i=0;idepth_merge,temp,sizeof(depth_t)*vert_count*num_agg_bfs, 206 | cudaMemcpyHostToDevice); 207 | cudaMemset(ggraph->depth_comp_last,0,sizeof(comp_t)*vert_count); 208 | cudaMemset(ggraph->depth_comp_curr,0,sizeof(comp_t)*vert_count); 209 | last_ct[0]=-1; 210 | 211 | depth_t level=0; 212 | tm_bfs=wtime(); 213 | ibfs 214 | ( 215 | src_list, 216 | i, 217 | gdata, 218 | ggraph, 219 | num_agg_bfs, 220 | vert_count, 221 | sw_level, 222 | last_ct, 223 | level, 224 | sml_shed, 225 | lrg_shed 226 | ); 227 | tm_bfs=wtime()-tm_bfs; 228 | reporter(tm_bfs, my_id, i); 229 | // std::cout<<"Traversal-time: "<2){ 232 | // validate_count ++; 233 | // if(cudaMemcpy(depth, ggraph->depth_merge, 234 | // sizeof(depth_t)*vert_count, 235 | // cudaMemcpyDeviceToHost)) 236 | // std::cout<<"copy result error\n"; 237 | 238 | // int ret = validate 239 | // (depth, adj_list, adj_card, beg_pos, vert_count); 240 | 241 | // std::cout<<"\nBFS result validation: "<< 242 | // ((ret == 0 )? "CORRECT (":"WRONG (")< 244 | // (agg_tr_edges, agg_tr_v, depth, adj_card, vert_count); 245 | // curr_teps = agg_tr_edges/(1000000000*tm_bfs); 246 | // average_teps= (curr_teps+average_teps*(validate_count-1)) 247 | // /validate_count; 248 | 249 | // std::cout<<"Traversed vertices: "<< agg_tr_v<<"\t\t\t" 250 | // <<"Traversed edges: "< 4 | 5 | static void HandleError( cudaError_t err, 6 | const char *file, 7 | int line ) { 8 | if (err != cudaSuccess) { 9 | printf( "%s in %s at line %d\n", \ 10 | cudaGetErrorString( err ), 11 | file, line ); 12 | exit( EXIT_FAILURE ); 13 | } 14 | } 15 | #define H_ERR( err ) \ 16 | (HandleError( err, __FILE__, __LINE__ )) 17 | 18 | 19 | 20 | ////////////////////////////////////////////////// 21 | //SCALE*THDS_NUMS*sizeof(int) should be 22 | //limited by the size of the shared memory 23 | ///////////////////////////////////////////////// 24 | ////////////////////////////////////////////////// 25 | #define THDS_NUM 256 26 | #define BLKS_NUM 256 27 | #define OMP_THDS 24 28 | #define V_NON_INC -1 29 | #define V_INI_HUB -2 30 | 31 | #define VALIDATE_TIMES 1 32 | enum ex_q_t 33 | { 34 | SML_Q, 35 | MID_Q, 36 | LRG_Q, 37 | NONE 38 | }; 39 | 40 | //-------------------------- 41 | typedef int index_t; 42 | typedef int vertex_t; 43 | typedef unsigned char depth_t; 44 | typedef uint4 comp_t; 45 | //-------------------------------- 46 | 47 | typedef struct CSR_Graph{ 48 | vertex_t* adj_list; 49 | index_t* adj_card; 50 | index_t* beg_pos; 51 | 52 | vertex_t* adj_list_d; 53 | index_t* adj_card_d; 54 | index_t* beg_pos_d; 55 | vertex_t* src_list; 56 | 57 | depth_t* depth_merge; 58 | 59 | //for direction-switching 60 | vertex_t* ex_sml_q; 61 | vertex_t* ex_mid_q; 62 | vertex_t* ex_lrg_q; 63 | index_t* ex_cat_sml_sz; 64 | index_t* ex_cat_mid_sz; 65 | index_t* ex_cat_lrg_sz; 66 | index_t* ex_sml_off; 67 | index_t* ex_mid_off; 68 | index_t* ex_lrg_off; 69 | 70 | comp_t *depth_comp_last; 71 | comp_t *depth_comp_curr; 72 | index_t vert_count; 73 | index_t edge_count; 74 | 75 | cudaStream_t gstream; 76 | } *csr_graph; 77 | 78 | typedef struct Traverse{ 79 | depth_t* depth_d; 80 | vertex_t* parent_d; 81 | index_t ex_q_sz; 82 | // vertex_t* ex_sml_q; 83 | // vertex_t* ex_mid_q; 84 | // vertex_t* ex_lrg_q; 85 | 86 | index_t *ex_sml_sz; 87 | index_t *ex_mid_sz; 88 | index_t *ex_lrg_sz; 89 | index_t *ex_sml_sz_d; 90 | index_t *ex_mid_sz_d; 91 | index_t *ex_lrg_sz_d; 92 | 93 | /// index_t* ex_cat_sml_sz; 94 | /// index_t* ex_cat_mid_sz; 95 | /// index_t* ex_cat_lrg_sz; 96 | /// index_t* ex_sml_off; 97 | /// index_t* ex_mid_off; 98 | /// index_t* ex_lrg_off; 99 | 100 | index_t* tr_edges_c_d; 101 | index_t* tr_edges_c_h; 102 | 103 | cudaStream_t *stream; 104 | } *tdata; 105 | 106 | 107 | #define VIS 0x02 108 | #define UNVIS 0x00 109 | #define FRT 0x01 110 | #define SET_VIS(a) ((a)=0x02) 111 | #define SET_FRT(a) ((a)=0x01) 112 | #define IS_FRT(a) ((a)==0x01) 113 | #define IS_VIS(a) ((a)==0x02) 114 | #define IS_UNVIS(a) ((a)==0x00) 115 | 116 | //---------------------------------- 117 | //GLOBAL VARIABLES 118 | //--------------------------------- 119 | //-------------------------------- 120 | #define INFTY 255 121 | #endif 122 | 123 | #ifndef EXTERN 124 | #define EXTERN 125 | //------------------- 126 | 127 | index_t ENABLE_BTUP; 128 | index_t SW_LEVEL; 129 | index_t agg_tr_edges;//already traversed edges 130 | index_t EDGES_C;//total edges in the graph 131 | 132 | //texture tex_adj_list[4]; 133 | //size_t tex_adj_off[4]; 134 | 135 | //texture tex_card; 136 | //texture tex_strt; 137 | //texture tex_depth; 138 | // 139 | //texture tex_sml_exq; 140 | //texture tex_mid_exq; 141 | //texture tex_lrg_exq; 142 | 143 | __device__ index_t hub_vert[16]; 144 | __device__ depth_t hub_stat[16]; 145 | __device__ index_t hub_card[16]; 146 | 147 | #define HUB_SZ 16 148 | #define HUB_BU_SZ 16//should be 1.25 of HUB_SZ 149 | //since there is no status 150 | //array in __shared__ mem 151 | #define HUB_CRITERIA 0 152 | #define Q_CARD 3 153 | 154 | #endif 155 | -------------------------------------------------------------------------------- /expander.cu: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 The George Washington University 3 | * Written by Hang Liu 4 | * Directed by Prof. Howie Huang 5 | * 6 | * https://www.seas.gwu.edu/~howie/ 7 | * Contact: iheartgraph@gmail.com 8 | * 9 | * 10 | * Please cite the following paper: 11 | * 12 | * Hang Liu, H. Howie Huang and Yang Hu. 2016. iBFS: Concurrent Breadth-First Search on GPUs. Proceedings of the 2016 International Conference on Management of Data. ACM. 13 | * 14 | * This file is part of iBFS. 15 | * 16 | * iBFS is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * iBFS is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with iBFS. If not, see . 28 | */ 29 | 30 | //Hang Dec/10/2013 31 | //Hang Mar/05/2015 32 | #include "gpu_ibfs.cuh" 33 | #include "util.h" 34 | 35 | __device__ void __sync_warp(int predicate){ 36 | while((!__all(predicate))){ 37 | ; 38 | } 39 | } 40 | 41 | //This kernel is executed by one thread 42 | __global__ void init_expand_sort 43 | ( 44 | vertex_t *src_list, 45 | index_t *beg_pos_d, 46 | index_t src_grp_off, 47 | index_t joint_count, 48 | index_t bit_count, 49 | index_t concurr_count, 50 | comp_t *depth_comp_last, 51 | comp_t *depth_comp_curr, 52 | index_t *ex_lrg_sz_d, 53 | vertex_t *ex_lrg_q_d 54 | ) 55 | { 56 | index_t tid=threadIdx.x+blockIdx.x*blockDim.x; 57 | const index_t GRNTY=blockDim.x*gridDim.x; 58 | 59 | while(tid>> 83 | ( 84 | src_list_d, 85 | beg_pos_d, 86 | src_grp_off, 87 | joint_count, 88 | bit_count, 89 | concurr_count, 90 | depth_comp_last, 91 | depth_comp_curr, 92 | ex_lrg_sz_d, 93 | ex_lrg_q_d 94 | ); 95 | } 96 | 97 | //+---------------------- 98 | //|for ex_sml_q_d expansion 99 | //+--------------------------- 100 | __global__ void td_expand_thd 101 | ( 102 | comp_t *depth_comp_last, 103 | comp_t *depth_comp_curr, 104 | depth_t curr_level, 105 | index_t ex_sml_sz, 106 | const vertex_t* __restrict__ ex_q_d, 107 | const index_t* __restrict__ beg_pos_d, 108 | const vertex_t* __restrict__ adj_list_d 109 | ) 110 | { 111 | const index_t q_sz = ex_sml_sz; 112 | const index_t GRNLTY = blockDim.x * gridDim.x; 113 | index_t tid = threadIdx.x+blockIdx.x*blockDim.x; 114 | 115 | //used for prefetching 116 | vertex_t ex_ver_curr; 117 | index_t end_curr; 118 | index_t beg_curr; 119 | vertex_t adj_vert; 120 | comp_t vert_depth, adj_depth; 121 | 122 | while(tid>5)+1)<<5); 293 | else 294 | end_curr_revised = end_curr; 295 | 296 | while(lane=1;i>>=1){ 303 | vert_depth.x|=__shfl_xor((int)vert_depth.x,i,32); 304 | vert_depth.y|=__shfl_xor((int)vert_depth.y,i,32); 305 | vert_depth.z|=__shfl_xor((int)vert_depth.z,i,32); 306 | vert_depth.w|=__shfl_xor((int)vert_depth.w,i,32); 307 | } 308 | 309 | lane+=vec_sz; 310 | } 311 | 312 | if(lane_s==0) depth_comp_curr[ex_ver_curr]=vert_depth; 313 | vec_id += GRNLTY; 314 | } 315 | } 316 | 317 | //+------------------------ 318 | //|ex_mid_q_d expansion 319 | //+------------------------------ 320 | __global__ void sw_expand_thd 321 | ( 322 | comp_t *depth_comp_last, 323 | comp_t *depth_comp_curr, 324 | depth_t curr_level, 325 | index_t ex_sz, 326 | const vertex_t* __restrict__ ex_q_d, 327 | const index_t* __restrict__ beg_pos_d, 328 | const vertex_t* __restrict__ adj_list_d 329 | ) 330 | { 331 | const index_t q_sz = ex_sz; 332 | index_t tid = threadIdx.x+blockIdx.x*blockDim.x; 333 | const index_t GRNLTY = blockDim.x*gridDim.x; 334 | 335 | vertex_t ex_ver_curr; 336 | index_t beg_curr, end_curr; 337 | comp_t adj_depth_curr, vert_depth; 338 | 339 | while(tid>> 370 | ( 371 | depth_comp_last, 372 | depth_comp_curr, 373 | curr_level, 374 | ex_sml_sz[0], 375 | ex_sml_q_d, 376 | beg_pos_d, 377 | adj_list_d 378 | ); 379 | 380 | td_expand_warp 381 | <<>> 382 | ( 383 | depth_comp_last, 384 | depth_comp_curr, 385 | curr_level, 386 | ex_mid_sz[0], 387 | ex_mid_q_d, 388 | beg_pos_d, 389 | adj_list_d 390 | ); 391 | 392 | 393 | td_expand_cta 394 | <<>> 395 | ( 396 | depth_comp_last, 397 | depth_comp_curr, 398 | curr_level, 399 | ex_lrg_sz[0], 400 | ex_lrg_q_d, 401 | beg_pos_d, 402 | adj_list_d 403 | ); 404 | 405 | for(index_t i=0;i>> 418 | ( 419 | depth_comp_last, 420 | depth_comp_curr, 421 | curr_level, 422 | ex_sml_sz[0], 423 | ex_sml_q_d, 424 | beg_pos_d, 425 | adj_list_d 426 | ); 427 | 428 | sw_expand_thd 429 | <<>> 430 | ( 431 | depth_comp_last, 432 | depth_comp_curr, 433 | curr_level, 434 | ex_mid_sz[0], 435 | ex_mid_q_d, 436 | beg_pos_d, 437 | adj_list_d 438 | ); 439 | 440 | sw_expand_thd 441 | <<>> 442 | ( 443 | depth_comp_last, 444 | depth_comp_curr, 445 | curr_level, 446 | ex_lrg_sz[0], 447 | ex_lrg_q_d, 448 | beg_pos_d, 449 | adj_list_d 450 | ); 451 | 452 | for(index_t i=0;i>> 465 | ( 466 | depth_comp_last, 467 | depth_comp_curr, 468 | curr_level, 469 | ex_sml_sz[0], 470 | ex_sml_q_d, 471 | beg_pos_d, 472 | adj_list_d 473 | ); 474 | 475 | sw_expand_warp 476 | <<>> 477 | ( 478 | depth_comp_last, 479 | depth_comp_curr, 480 | curr_level, 481 | ex_mid_sz[0], 482 | ex_mid_q_d, 483 | beg_pos_d, 484 | adj_list_d 485 | ); 486 | 487 | sw_expand_warp 488 | <<>> 489 | ( 490 | depth_comp_last, 491 | depth_comp_curr, 492 | curr_level, 493 | ex_lrg_sz[0], 494 | ex_lrg_q_d, 495 | beg_pos_d, 496 | adj_list_d 497 | ); 498 | 499 | for(index_t i=0;i 16 | __global__ void init_expand_sort 17 | ( 18 | vertex_t *src_list, 19 | index_t src_grp_off, 20 | depth_t *depth_merge, 21 | comp_t *depth_comp_last, 22 | comp_t *depth_comp_curr, 23 | index_t num_agg_bfs, 24 | vertex_t *parent_d, 25 | index_t *adj_card_d, 26 | index_t *ex_sml_sz_d, 27 | index_t *ex_mid_sz_d, 28 | index_t *ex_lrg_sz_d, 29 | vertex_t *ex_sml_q, 30 | vertex_t *ex_mid_q, 31 | vertex_t *ex_lrg_q, 32 | index_t vert_count, 33 | index_t sml_shed, 34 | index_t lrg_shed 35 | ) 36 | { 37 | // parent_d[src_v] =-1; 38 | if(threadIdx.x==num_agg_bfs){ 39 | ex_sml_sz_d[0] = 0; 40 | ex_mid_sz_d[0] = 0; 41 | ex_lrg_sz_d[0] = num_agg_bfs; 42 | } 43 | 44 | if(threadIdx.x 81 | void init_bfs( 82 | vertex_t *src_v, 83 | index_t src_grp_off, 84 | tdata *gdata, 85 | csr_graph ggraph, 86 | index_t num_agg_bfs, 87 | index_t sml_shed, 88 | index_t lrg_shed 89 | ){ 90 | 91 | init_expand_sort 92 | 93 | <<<1,THDS_NUM>>> 94 | ( 95 | ggraph->src_list, 96 | src_grp_off, 97 | ggraph->depth_merge, 98 | ggraph->depth_comp_last, 99 | ggraph->depth_comp_curr, 100 | num_agg_bfs, 101 | gdata[0]->parent_d, 102 | ggraph->adj_card_d, 103 | gdata[0]->ex_sml_sz_d, 104 | gdata[0]->ex_mid_sz_d, 105 | gdata[0]->ex_lrg_sz_d, 106 | ggraph->ex_sml_q, 107 | ggraph->ex_mid_q, 108 | ggraph->ex_lrg_q, 109 | ggraph->vert_count, 110 | sml_shed, 111 | lrg_shed 112 | ); 113 | 114 | //cudaDeviceSynchronize(); 115 | // index_t vert_count=ggraph->vert_count; 116 | // comp_t *d_status_curr,*d_status_last; 117 | // cudaMallocHost((void **)&d_status_curr, sizeof(comp_t)*vert_count); 118 | // cudaMallocHost((void **)&d_status_last, sizeof(comp_t)*vert_count); 119 | // cudaMemcpy(d_status_curr, ggraph->depth_comp_curr,sizeof(comp_t)*vert_count,cudaMemcpyDeviceToHost); 120 | // cudaMemcpy(d_status_last, ggraph->depth_comp_last,sizeof(comp_t)*vert_count,cudaMemcpyDeviceToHost); 121 | // 122 | // int ft_count=0; int diff=0; 123 | // for(int i=0;iadj_card[i]>0) ft_count++; 126 | // } 127 | // std::cout<<"ft_count-diff "< 140 | __global__ void td_expand_thd 141 | ( 142 | comp_t *depth_comp_last, 143 | comp_t *depth_comp_curr, 144 | index_t num_agg_bfs, 145 | vertex_t *parent_d, 146 | depth_t curr_level, 147 | index_t ex_sml_sz, 148 | const vertex_t* __restrict__ ex_q_d, 149 | const index_t* __restrict__ adj_card_d, 150 | const index_t* __restrict__ beg_pos_d, 151 | const vertex_t* __restrict__ adj_list_d 152 | ) 153 | { 154 | const index_t q_sz = ex_sml_sz; 155 | const index_t GRNLTY = blockDim.x * gridDim.x; 156 | index_t tid = threadIdx.x+blockIdx.x*blockDim.x; 157 | 158 | //used for prefetching 159 | vertex_t ex_ver_curr; 160 | index_t card_curr; 161 | index_t beg_pos_curr; 162 | vertex_t adj_vert; 163 | comp_t vert_depth,adj_depth; 164 | unsigned int vert_depth_vec[4]; 165 | 166 | while(tid 208 | __global__ void td_expand_warp 209 | ( 210 | comp_t *depth_comp_last, 211 | comp_t *depth_comp_curr, 212 | index_t num_agg_bfs, 213 | vertex_t *parent_d, 214 | depth_t curr_level, 215 | index_t ex_mid_sz, 216 | const vertex_t* __restrict__ ex_q_d, 217 | const index_t* __restrict__ adj_card_d, 218 | const index_t* __restrict__ beg_pos_d, 219 | const vertex_t* __restrict__ adj_list_d 220 | ) 221 | { 222 | const index_t q_sz = ex_mid_sz; 223 | const index_t vec_sz = 32; 224 | const index_t TID = threadIdx.x+blockIdx.x*blockDim.x; 225 | const index_t lane_s = TID & (vec_sz-1); 226 | const index_t GRNLTY = (blockDim.x*gridDim.x)/vec_sz; 227 | index_t vec_id = TID/vec_sz; 228 | 229 | vertex_t ex_ver_curr,adj_vert; 230 | index_t card_curr; 231 | index_t beg_pos_curr; 232 | comp_t vert_depth,adj_depth; 233 | unsigned int vert_depth_vec[4]; 234 | 235 | while(vec_id 276 | __global__ void td_expand_cta 277 | ( 278 | comp_t *depth_comp_last, 279 | comp_t *depth_comp_curr, 280 | index_t num_agg_bfs, 281 | vertex_t *parent_d, 282 | depth_t curr_level, 283 | index_t ex_lrg_sz, 284 | const vertex_t* __restrict__ ex_q_d, 285 | const index_t* __restrict__ adj_card_d, 286 | const index_t* __restrict__ beg_pos_d, 287 | const vertex_t* __restrict__ adj_list_d 288 | ) 289 | { 290 | const index_t q_sz = ex_lrg_sz; 291 | index_t vec_id = blockIdx.x; 292 | 293 | vertex_t ex_ver_curr,adj_vert; 294 | index_t card_curr; 295 | index_t beg_pos_curr; 296 | comp_t vert_depth,adj_depth; 297 | unsigned int vert_depth_vec[4]; 298 | 299 | while(vec_id 341 | __global__ void sw_expand_warp 342 | ( 343 | comp_t *depth_comp_last, 344 | comp_t *depth_comp_curr, 345 | index_t num_agg_bfs, 346 | vertex_t *parent_d, 347 | depth_t curr_level, 348 | index_t ex_sz, 349 | const vertex_t* __restrict__ ex_q_d, 350 | const index_t* __restrict__ adj_card_d, 351 | const index_t* __restrict__ beg_pos_d, 352 | const vertex_t* __restrict__ adj_list_d 353 | ) 354 | { 355 | const index_t q_sz = ex_sz; 356 | const index_t vec_sz = 32; 357 | const index_t TID = threadIdx.x+blockIdx.x*blockDim.x; 358 | const index_t lane_s = TID & (vec_sz-1); 359 | const index_t GRNLTY = (blockDim.x*gridDim.x)/vec_sz; 360 | index_t vec_id = TID/vec_sz; 361 | 362 | vertex_t ex_ver_curr; 363 | index_t card_curr, card_curr_revised; 364 | index_t beg_pos_curr; 365 | unsigned int vert_depth_vec[4]; 366 | comp_t vert_depth; 367 | 368 | while(vec_id>5)+1)<<5); 383 | else 384 | card_curr_revised = card_curr; 385 | 386 | card_curr+= beg_pos_curr; 387 | card_curr_revised+=beg_pos_curr; 388 | while(lane=1;i>>=1){ 405 | vert_depth_vec[0]|=__shfl_xor((int)vert_depth_vec[0],i,32); 406 | vert_depth_vec[1]|=__shfl_xor((int)vert_depth_vec[1],i,32); 407 | vert_depth_vec[2]|=__shfl_xor((int)vert_depth_vec[2],i,32); 408 | vert_depth_vec[3]|=__shfl_xor((int)vert_depth_vec[3],i,32); 409 | } 410 | lane+=vec_sz; 411 | } 412 | 413 | if(lane_s==0){ 414 | depth_comp_curr[ex_ver_curr].x=vert_depth_vec[0]; 415 | depth_comp_curr[ex_ver_curr].y=vert_depth_vec[1]; 416 | depth_comp_curr[ex_ver_curr].z=vert_depth_vec[2]; 417 | depth_comp_curr[ex_ver_curr].w=vert_depth_vec[3]; 418 | } 419 | 420 | vec_id += GRNLTY; 421 | } 422 | } 423 | 424 | //+------------------------ 425 | //|ex_mid_q expansion 426 | //+------------------------------ 427 | template 431 | __global__ void sw_expand_thd 432 | ( 433 | comp_t *depth_comp_last, 434 | comp_t *depth_comp_curr, 435 | index_t num_agg_bfs, 436 | vertex_t *parent_d, 437 | depth_t curr_level, 438 | index_t ex_sz, 439 | const vertex_t* __restrict__ ex_q_d, 440 | const index_t* __restrict__ adj_card_d, 441 | const index_t* __restrict__ beg_pos_d, 442 | const vertex_t* __restrict__ adj_list_d 443 | ) 444 | { 445 | const index_t q_sz = ex_sz; 446 | index_t tid = threadIdx.x+blockIdx.x*blockDim.x; 447 | const index_t GRNLTY = blockDim.x*gridDim.x; 448 | 449 | vertex_t ex_ver_curr; 450 | index_t card_curr; 451 | index_t beg_pos_curr; 452 | comp_t vert_depth; 453 | unsigned int vert_depth_vec[4]; 454 | 455 | while(tid 497 | void td_expand 498 | ( 499 | tdata *gdata, 500 | csr_graph ggraph, 501 | index_t num_agg_bfs, 502 | depth_t curr_level 503 | ) 504 | { 505 | td_expand_thd 506 | <<stream[0]>>> 507 | ( 508 | ggraph->depth_comp_last, 509 | ggraph->depth_comp_curr, 510 | num_agg_bfs, 511 | gdata[0]->parent_d, 512 | curr_level, 513 | gdata[0]->ex_sml_sz[0], 514 | ggraph->ex_sml_q, 515 | ggraph->adj_card_d, 516 | ggraph->beg_pos_d, 517 | ggraph->adj_list_d 518 | ); 519 | 520 | td_expand_warp 521 | <<stream[1]>>> 522 | ( 523 | ggraph->depth_comp_last, 524 | ggraph->depth_comp_curr, 525 | num_agg_bfs, 526 | gdata[0]->parent_d, 527 | curr_level, 528 | gdata[0]->ex_mid_sz[0], 529 | ggraph->ex_mid_q, 530 | ggraph->adj_card_d, 531 | ggraph->beg_pos_d, 532 | ggraph->adj_list_d 533 | ); 534 | 535 | 536 | td_expand_cta 537 | <<stream[2]>>> 538 | ( 539 | ggraph->depth_comp_last, 540 | ggraph->depth_comp_curr, 541 | num_agg_bfs, 542 | gdata[0]->parent_d, 543 | curr_level, 544 | gdata[0]->ex_lrg_sz[0], 545 | ggraph->ex_lrg_q, 546 | ggraph->adj_card_d, 547 | ggraph->beg_pos_d, 548 | ggraph->adj_list_d 549 | ); 550 | 551 | for(index_t i=0;istream[i]); 553 | } 554 | 555 | //+---------------------- 556 | //|CLFY_EXPAND_SORT 557 | //+---------------------- 558 | template 561 | void bu_expand 562 | ( 563 | tdata *gdata, 564 | csr_graph ggraph, 565 | index_t num_agg_bfs, 566 | depth_t curr_level 567 | ) 568 | { 569 | sw_expand_thd 570 | <<stream[0]>>> 571 | ( 572 | ggraph->depth_comp_last, 573 | ggraph->depth_comp_curr, 574 | num_agg_bfs, 575 | gdata[0]->parent_d, 576 | curr_level, 577 | gdata[0]->ex_sml_sz[0], 578 | ggraph->ex_sml_q, 579 | ggraph->adj_card_d, 580 | ggraph->beg_pos_d, 581 | ggraph->adj_list_d 582 | ); 583 | 584 | sw_expand_thd 585 | <<stream[1]>>> 586 | ( 587 | ggraph->depth_comp_last, 588 | ggraph->depth_comp_curr, 589 | num_agg_bfs, 590 | gdata[0]->parent_d, 591 | curr_level, 592 | gdata[0]->ex_mid_sz[0], 593 | ggraph->ex_mid_q, 594 | ggraph->adj_card_d, 595 | ggraph->beg_pos_d, 596 | ggraph->adj_list_d 597 | ); 598 | 599 | sw_expand_thd 600 | <<stream[2]>>> 601 | ( 602 | ggraph->depth_comp_last, 603 | ggraph->depth_comp_curr, 604 | num_agg_bfs, 605 | gdata[0]->parent_d, 606 | curr_level, 607 | gdata[0]->ex_lrg_sz[0], 608 | ggraph->ex_lrg_q, 609 | ggraph->adj_card_d, 610 | ggraph->beg_pos_d, 611 | ggraph->adj_list_d 612 | ); 613 | 614 | for(index_t i=0;istream[i]); 616 | } 617 | 618 | //+---------------------- 619 | //|CLFY_EXPAND_SORT 620 | //+---------------------- 621 | template 625 | void sw_expand 626 | ( 627 | tdata *gdata, 628 | csr_graph ggraph, 629 | index_t num_agg_bfs, 630 | depth_t curr_level 631 | ) 632 | { 633 | sw_expand_thd 634 | <<stream[0]>>> 635 | ( 636 | ggraph->depth_comp_last, 637 | ggraph->depth_comp_curr, 638 | num_agg_bfs, 639 | gdata[0]->parent_d, 640 | curr_level, 641 | gdata[0]->ex_sml_sz[0], 642 | ggraph->ex_sml_q, 643 | ggraph->adj_card_d, 644 | ggraph->beg_pos_d, 645 | ggraph->adj_list_d 646 | ); 647 | 648 | sw_expand_warp 649 | <<stream[1]>>> 650 | ( 651 | ggraph->depth_comp_last, 652 | ggraph->depth_comp_curr, 653 | num_agg_bfs, 654 | gdata[0]->parent_d, 655 | curr_level, 656 | gdata[0]->ex_mid_sz[0], 657 | ggraph->ex_mid_q, 658 | ggraph->adj_card_d, 659 | ggraph->beg_pos_d, 660 | ggraph->adj_list_d 661 | ); 662 | 663 | sw_expand_warp 664 | <<stream[2]>>> 665 | ( 666 | ggraph->depth_comp_last, 667 | ggraph->depth_comp_curr, 668 | num_agg_bfs, 669 | gdata[0]->parent_d, 670 | curr_level, 671 | gdata[0]->ex_lrg_sz[0], 672 | ggraph->ex_lrg_q, 673 | ggraph->adj_card_d, 674 | ggraph->beg_pos_d, 675 | ggraph->adj_list_d 676 | ); 677 | 678 | for(index_t i=0;istream[i]); 680 | } 681 | 682 | 683 | template 687 | void expander( 688 | tdata *gdata, 689 | csr_graph ggraph, 690 | index_t num_agg_bfs, 691 | index_t sw_level, 692 | depth_t level 693 | ) 694 | { 695 | if(level<=sw_level) 696 | td_expand 697 | 698 | ( 699 | gdata, 700 | ggraph, 701 | num_agg_bfs, 702 | level 703 | ); 704 | else if((level==sw_level+1||level==sw_level+2||level==sw_level+3)) 705 | sw_expand 706 | 707 | ( 708 | gdata, 709 | ggraph, 710 | num_agg_bfs, 711 | level 712 | ); 713 | else{//also use merged fq 714 | bu_expand//but do not consider imbalance issue 715 | 716 | ( 717 | gdata, 718 | ggraph, 719 | num_agg_bfs, 720 | level 721 | ); 722 | } 723 | } 724 | -------------------------------------------------------------------------------- /gen_script.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | declare -a name=(fb hw kg1 ok pk rd rm tw wk) 4 | for file in ${name[@]} 5 | do 6 | for ((i=1;i<=32;i=i*2)) 7 | do 8 | #cp jobScript"$i"gpu-fb jobScript"$i"gpu-$file 9 | sed -i "s/TG-CCR120025/TG-CTS100002/g" jobScript"$i"gpu-$file 10 | #sed -i "s/"$i"gpu/-"$i"gpu-$file/g" jobScript"$i"gpu 11 | done 12 | done 13 | 14 | -------------------------------------------------------------------------------- /get_time.bash: -------------------------------------------------------------------------------- 1 | declare -a data=(rm) 2 | for arr in ${data[@]} 3 | do 4 | echo "Processing $arr ... " 5 | for ((i=1;i<=32;i=i*2)) 6 | do 7 | file=$(find ./ -maxdepth 1 -iname "traversal-"$i"gpu-$arr.o*") 8 | 9 | if [ -f $file ] 10 | then 11 | tm=$(grep "Traversal-iter" $file | awk -v tm=0 -v count=0 '{tm+=$2;count++}END{print tm}') 12 | echo $tm 13 | fi 14 | done 15 | echo "----------------" 16 | done 17 | -------------------------------------------------------------------------------- /gpu_ibfs.cu: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 The George Washington University 3 | * Written by Hang Liu 4 | * Directed by Prof. Howie Huang 5 | * 6 | * https://www.seas.gwu.edu/~howie/ 7 | * Contact: iheartgraph@gmail.com 8 | * 9 | * 10 | * Please cite the following paper: 11 | * 12 | * Hang Liu, H. Howie Huang and Yang Hu. 2016. iBFS: Concurrent Breadth-First Search on GPUs. Proceedings of the 2016 International Conference on Management of Data. ACM. 13 | * 14 | * This file is part of iBFS. 15 | * 16 | * iBFS is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * iBFS is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with iBFS. If not, see . 28 | */ 29 | 30 | #include "scan.cuh" 31 | #include "wtime.h" 32 | #include "validate.h" 33 | #include "gpu_ibfs.cuh" 34 | 35 | //constructor 36 | gpu_ibfs:: 37 | gpu_ibfs( 38 | const graph* g, 39 | index_t concurr_count, 40 | depth_t sw_level, 41 | index_t gpu_count, 42 | index_t sml_shed, 43 | index_t lrg_shed) 44 | :g(g),sw_level(sw_level),gpu_count(gpu_count), 45 | sml_shed(sml_shed),lrg_shed(lrg_shed),concurr_count(concurr_count) 46 | { 47 | bit_count = sizeof(comp_t)<<3; 48 | joint_count = (index_t)ceil((concurr_count*1.0)/bit_count); 49 | 50 | std::cout<<"joint_count vs bit_count: "<edge_count; 56 | const size_t vert_sz = sizeof(vertex_t)*g->vert_count; 57 | const size_t index_sz = sizeof(index_t)*g->vert_count; 58 | const size_t comp_sz = sizeof(comp_t)*g->vert_count*joint_count; 59 | const size_t src_sz = sizeof(vertex_t)*g->src_count; 60 | 61 | H_ERR(cudaMalloc((void **)&beg_pos_d, index_sz)); 62 | H_ERR(cudaMalloc((void **)&adj_list_d, edge_sz)); 63 | gpu_bytes += edge_sz+(index_sz); 64 | 65 | H_ERR(cudaMalloc((void **)&cat_sml_off_d, cat_index_sz)); 66 | H_ERR(cudaMalloc((void **)&cat_mid_off_d, cat_index_sz)); 67 | H_ERR(cudaMalloc((void **)&cat_lrg_off_d, cat_index_sz)); 68 | H_ERR(cudaMalloc((void **)&cat_sml_sz_d, cat_index_sz)); 69 | H_ERR(cudaMalloc((void **)&cat_mid_sz_d, cat_index_sz)); 70 | H_ERR(cudaMalloc((void **)&cat_lrg_sz_d, cat_index_sz)); 71 | gpu_bytes+=(cat_index_sz*6); 72 | 73 | H_ERR(cudaMalloc((void **)&ex_sml_q_d, vert_sz)); 74 | H_ERR(cudaMalloc((void **)&ex_mid_q_d, vert_sz)); 75 | H_ERR(cudaMalloc((void **)&ex_lrg_q_d, vert_sz)); 76 | gpu_bytes+=(vert_sz*3); 77 | 78 | H_ERR(cudaMalloc((void **)&src_list_d,src_sz)); 79 | H_ERR(cudaMalloc((void **)&depth_comp_last,comp_sz)); 80 | H_ERR(cudaMalloc((void **)&depth_comp_curr,comp_sz)); 81 | cudaStreamCreate(&gstream); 82 | 83 | gpu_bytes+=(comp_sz*2)+src_sz; 84 | 85 | H_ERR(cudaHostAlloc((void **)&is_done, 86 | sizeof(bool),cudaHostAllocMapped)); 87 | H_ERR(cudaHostGetDevicePointer((void **)&is_done_d, 88 | (void*)is_done,0)); 89 | 90 | //+---------------------- 91 | //|FOR CLASSIFICATION 92 | //+---------------------------- 93 | H_ERR(cudaHostAlloc((void **)&ex_sml_sz, 94 | sizeof(index_t),cudaHostAllocMapped)); 95 | H_ERR(cudaHostAlloc((void **)&ex_mid_sz, 96 | sizeof(index_t),cudaHostAllocMapped)); 97 | H_ERR(cudaHostAlloc((void **)&ex_lrg_sz, 98 | sizeof(index_t),cudaHostAllocMapped)); 99 | H_ERR(cudaHostGetDevicePointer((void **)&ex_sml_sz_d, 100 | (void*)ex_sml_sz,0)); 101 | H_ERR(cudaHostGetDevicePointer((void **)&ex_mid_sz_d, 102 | (void*)ex_mid_sz,0)); 103 | H_ERR(cudaHostGetDevicePointer((void **)&ex_lrg_sz_d, 104 | (void*)ex_lrg_sz,0)); 105 | 106 | stream=(cudaStream_t *)malloc(sizeof(cudaStream_t)*Q_CARD); 107 | for(index_t j=0;jbeg_pos,index_sz, 112 | cudaMemcpyHostToDevice)); 113 | H_ERR(cudaMemcpy(adj_list_d,g->csr,edge_sz, 114 | cudaMemcpyHostToDevice)); 115 | H_ERR(cudaMemcpy(src_list_d,g->src_list,src_sz, 116 | cudaMemcpyHostToDevice)); 117 | } 118 | 119 | -------------------------------------------------------------------------------- /gpu_ibfs.cuh: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 The George Washington University 3 | * Written by Hang Liu 4 | * Directed by Prof. Howie Huang 5 | * 6 | * https://www.seas.gwu.edu/~howie/ 7 | * Contact: iheartgraph@gmail.com 8 | * 9 | * 10 | * Please cite the following paper: 11 | * 12 | * Hang Liu, H. Howie Huang and Yang Hu. 2016. iBFS: Concurrent Breadth-First Search on GPUs. Proceedings of the 2016 International Conference on Management of Data. ACM. 13 | * 14 | * This file is part of iBFS. 15 | * 16 | * iBFS is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * iBFS is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with iBFS. If not, see . 28 | */ 29 | 30 | //Graph format: Json based format: [src_id, src_weigh,[[connected_ver_0, edge_weight],[connected_ver_1, edge_weight],[connected_ver_2, edge_weight]]] 31 | //Storage format: 32 | //struct{ 33 | // int: src_ver 34 | // Arr: [ver_0|ver_1|ver_2|...] 35 | // Int: num_conn_ver 36 | // } 37 | #ifndef GPU_IBFS_H 38 | #define GPU_IBFS_H 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include "util.h" 46 | #include "wtime.h" 47 | #include "graph.h" 48 | 49 | class gpu_ibfs{ 50 | 51 | //variable 52 | public: 53 | const graph *g; 54 | 55 | vertex_t* src_list_d; 56 | vertex_t* adj_list_d; 57 | index_t* beg_pos_d; 58 | vertex_t* ex_sml_q_d; 59 | vertex_t* ex_mid_q_d; 60 | vertex_t* ex_lrg_q_d; 61 | index_t* cat_sml_sz_d; 62 | index_t* cat_mid_sz_d; 63 | index_t* cat_lrg_sz_d; 64 | index_t* cat_sml_off_d; 65 | index_t* cat_mid_off_d; 66 | index_t* cat_lrg_off_d; 67 | 68 | index_t *ex_sml_sz; 69 | index_t *ex_mid_sz; 70 | index_t *ex_lrg_sz; 71 | index_t *ex_sml_sz_d; 72 | index_t *ex_mid_sz_d; 73 | index_t *ex_lrg_sz_d; 74 | 75 | comp_t *depth_comp_last; 76 | comp_t *depth_comp_curr; 77 | cudaStream_t *stream, gstream; 78 | 79 | index_t sml_shed; 80 | index_t lrg_shed; 81 | index_t gpu_count; 82 | index_t *gpu_ranger; 83 | index_t joint_count; 84 | index_t bit_count; 85 | index_t concurr_count; 86 | index_t sw_level; 87 | bool *is_done; 88 | bool *is_done_d; 89 | 90 | //constructor 91 | public: 92 | gpu_ibfs(){}; 93 | gpu_ibfs( 94 | const graph *g, 95 | index_t concurr_count, 96 | depth_t sw_level, 97 | index_t gpu_count, 98 | index_t sml_shed, 99 | index_t lrg_shed); 100 | ~gpu_ibfs(){}; 101 | 102 | //functions 103 | public: 104 | int write_result(); 105 | 106 | void traversal(index_t src_grp_off); 107 | void init_bfs(index_t src_grp_off); 108 | void debugger(index_t); 109 | 110 | //expander series 111 | void expander(depth_t level); 112 | void bu_expand(depth_t level); 113 | void td_expand(depth_t level); 114 | void sw_expand(depth_t level); 115 | 116 | //inspector series 117 | void inspector(depth_t level); 118 | void td_inspect(depth_t level); 119 | void sw_inspect(depth_t level); 120 | }; 121 | #endif 122 | -------------------------------------------------------------------------------- /graph.cu: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 The George Washington University 3 | * Written by Hang Liu 4 | * Directed by Prof. Howie Huang 5 | * 6 | * https://www.seas.gwu.edu/~howie/ 7 | * Contact: iheartgraph@gmail.com 8 | * 9 | * 10 | * Please cite the following paper: 11 | * 12 | * Hang Liu, H. Howie Huang and Yang Hu. 2016. iBFS: Concurrent Breadth-First Search on GPUs. Proceedings of the 2016 International Conference on Management of Data. ACM. 13 | * 14 | * This file is part of iBFS. 15 | * 16 | * iBFS is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * iBFS is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with iBFS. If not, see . 28 | */ 29 | 30 | #include "graph.h" 31 | 32 | inline bool deep_than_two( 33 | vertex_t src, 34 | depth_t *depth, 35 | index_t *beg_pos, 36 | vertex_t *csr 37 | ){ 38 | depth[src]=0; 39 | 40 | //two level DFS 41 | index_t beg=beg_pos[src]; 42 | index_t end=beg_pos[src+1]; 43 | for(;beg 8 | #include 9 | #include "GroupBy.cuh" 10 | 11 | #define FILE_NOT_EXIST 1 12 | #define FILE_EXIST 0 13 | 14 | template 15 | void progress( 16 | index_t &report, 17 | index_t beg_time, 18 | int tid, 19 | index_t prc_line 20 | ){ 21 | if(prc_line>report && tid==0){ 22 | std::cout< 29 | bool deep_than_two( 30 | vertex_t src, 31 | vertex_t *currq, 32 | vertex_t *nextq, 33 | depth_t *depth, 34 | index_t *adj_card, 35 | index_t *beg_pos, 36 | vertex_t *adj_list 37 | ){ 38 | 39 | index_t curr_sz=1; 40 | index_t next_sz=0; 41 | currq[0]=src; 42 | depth[src]=0; 43 | //sequential check if traversal larger than 2 44 | for(index_t level=0;;level++) 45 | { 46 | next_sz=0; 47 | for(index_t i=0;i 75 | void arrange_src 76 | ( 77 | int world_sz, 78 | int my_id, 79 | vertex_t *glb_src_list, 80 | index_t glb_src_count, 81 | vertex_t* &src_list, 82 | index_t &src_count){ 83 | 84 | src_count=glb_src_count/world_sz; 85 | if(glb_src_count != src_count * world_sz){ 86 | std::cout<<"Work not even!\n"; 87 | exit(-1); 88 | } 89 | 90 | src_list=new vertex_t[src_count]; 91 | int src_off=my_id*src_count; 92 | 93 | memcpy(src_list,glb_src_list+src_off, 94 | sizeof(vertex_t)*src_count); 95 | } 96 | 97 | 98 | 99 | template< typename vertex_t, 100 | typename index_t> 101 | int read_src_v( 102 | vertex_t* &glb_src_list, 103 | index_t &glb_src_count, 104 | std::string filename 105 | ) 106 | { 107 | std::stringstream ss; 108 | std::string str; 109 | std::ifstream myfile(filename.c_str()); 110 | 111 | //count num source in input.dat 112 | //one line is a source 113 | if(!myfile.good()) return FILE_NOT_EXIST; 114 | glb_src_count=0; 115 | while(std::getline(myfile, str)) 116 | glb_src_count++; 117 | myfile.close(); 118 | //std::cout<<"Read input.dat: "<>glb_src_list[ptr]; 128 | ptr++; 129 | } 130 | myfile.close(); 131 | 132 | return FILE_EXIST; 133 | } 134 | 135 | //this function aims to get the vertex list from ss 136 | template 137 | int proc_json( 138 | std::string kron_addr, 139 | index_t vert_count, 140 | index_t edge_count, 141 | vertex_t* adj_list, 142 | index_t* adj_card, 143 | index_t* beg_pos) 144 | { 145 | 146 | double beg_time; 147 | std::stringstream ss; 148 | std::string sline; 149 | index_t i; 150 | index_t *card_sum = new index_t[OMP_THDS]; 151 | beg_time=wtime(); 152 | //read card and formulate beg_pos 153 | std::cout<<"\n\nReading cardinality ... \n"; 154 | #pragma omp parallel \ 155 | private(i) num_threads(OMP_THDS) 156 | { 157 | index_t report=1; 158 | index_t prc_line=0; 159 | vertex_t beg_vert,end_vert,vert_id; 160 | std::string line; 161 | std::stringstream ss; 162 | int tid=omp_get_thread_num(); 163 | ss.str(""); 164 | ss.clear(); 165 | 166 | //+--------- 167 | //Assuming big file is partioned into small 168 | // files continuously and named sequentially. 169 | //+---- 170 | //example 1,2,3,4,5 partioned into three files 171 | //file-0: 1,2; file-1: 3,4; file-2: 5; 172 | //+--------------------------------------- 173 | ss<(report,beg_time,tid,prc_line); 181 | ss.str(""); 182 | ss.clear(); 183 | ss<>vert_id; 185 | ss>>adj_card[vert_id]; 186 | card_sum[tid]+=adj_card[vert_id]; 187 | if(prc_line==0) beg_vert=vert_id; 188 | prc_line++; 189 | } 190 | end_vert=vert_id; 191 | file.close(); 192 | }else{std::cout<<"card file wrong\n";exit(-4);} 193 | #pragma omp barrier 194 | 195 | beg_pos[beg_vert]=0; 196 | for(i=0;i(report,beg_time,tid,prc_line); 225 | //top-down 226 | ss.str(""); 227 | ss.clear(); 228 | ss<>vert_id; 230 | ss>>temp;//card 231 | if(temp!=beg_pos[vert_id+1]-beg_pos[vert_id]){ 232 | std::cout<>adj_list[beg_pos[vert_id]+i]; 238 | prc_line++; 239 | } 240 | file.close(); 241 | }else{std::cout<<"kron file wrong\n";exit(-4);} 242 | } 243 | return 0; 244 | } 245 | 246 | template 247 | graph 248 | ::graph( 249 | graph_reader *g, 250 | index_t sw_level, 251 | index_t vert_count, 252 | index_t edge_count, 253 | index_t num_groups, 254 | index_t num_agg_bfs, 255 | int world_sz, int my_id, 256 | index_t gpu_id, 257 | index_t sml_shed, 258 | index_t lrg_shed 259 | ):gpu_id(gpu_id),vert_count(vert_count),edge_count(edge_count), 260 | num_agg_bfs(num_agg_bfs),sml_shed(sml_shed),lrg_shed(lrg_shed), 261 | sw_level(sw_level), world_sz(world_sz), my_id(my_id) 262 | { 263 | 264 | index_t glb_src_count; 265 | vertex_t *glb_src_list; 266 | 267 | //traversal data 268 | gdata = new tdata[num_agg_bfs]; 269 | for(index_t i=0;ivert_count=g->vert_count; 275 | ggraph->edge_count=g->edge_count; 276 | ggraph->adj_list=g->csr; 277 | ggraph->adj_card=new index_t[vert_count]; 278 | ggraph->beg_pos=g->beg_pos; 279 | EDGES_C = edge_count;//bad programming style, related to direction-switch 280 | 281 | 282 | for(vertex_t i = 0; i < g->vert_count; i++) 283 | ggraph->adj_card[i] = g->beg_pos[i+1] - g->beg_pos[i]; 284 | 285 | double timer=wtime(); 286 | std::cout<<"Loading edges ... \n"; 287 | //proc_json( 288 | // kron_addr, 289 | // vert_count, 290 | // edge_count, 291 | // ggraph->adj_list, 292 | // ggraph->adj_card, 293 | // ggraph->beg_pos); 294 | std::cout<<"Loading edges time: "< 316 | (glb_src_list[i],currq,nextq,depth, 317 | ggraph->adj_card,ggraph->beg_pos,ggraph->adj_list)){ 318 | --i;continue; 319 | } 320 | 321 | //Not repeated 322 | for(index_t j = 0; j< i; j++) 323 | if(glb_src_list[j] == glb_src_list[i]){ 324 | --i;continue; 325 | } 326 | } 327 | 328 | delete[] currq; 329 | delete[] nextq; 330 | delete[] depth; 331 | }; 332 | 333 | #ifdef GROUPBY 334 | std::cout<<"before\n"; 335 | vertex_t *glb_new_list=new vertex_t[glb_src_count]; 336 | std::cout<<"after\n"; 337 | GroupBy(glb_src_count,glb_src_list,glb_new_list,ggraph); 338 | memcpy(glb_src_list,glb_new_list,sizeof(vertex_t)*glb_src_count); 339 | #endif 340 | 341 | arrange_src( 342 | world_sz, my_id, glb_src_list, glb_src_count, src_list, src_count); 343 | std::cout<<"Global-source-count vs src_count: "<src_ver 354 | <<"("<num_conn_ver 355 | <<","<depth<<"): "; 356 | for(int i=0;inum_conn_ver;i++) 357 | std::cout<conn_ver_list[i]<<","; 358 | std::cout<<"\n"; 359 | } 360 | #endif 361 | 362 | } 363 | -------------------------------------------------------------------------------- /graph.h: -------------------------------------------------------------------------------- 1 | //Graph format: Json based format: [src_id, src_weigh,[[connected_ver_0, edge_weight],[connected_ver_1, edge_weight],[connected_ver_2, edge_weight]]] 2 | //Storage format: 3 | //struct{ 4 | // int: src_ver 5 | // Arr: [ver_0|ver_1|ver_2|...] 6 | // Int: num_conn_ver 7 | // } 8 | #ifndef GRAPH_H 9 | #define GRAPH_H 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "comm.h" 17 | #include "graph_reader.h" 18 | 19 | template 20 | < typename vertex_t, 21 | typename index_t, 22 | typename depth_t> 23 | class graph{ 24 | 25 | //variable 26 | public: 27 | vertex_t *src_list; 28 | index_t src_count; 29 | index_t edge_count; 30 | index_t vert_count; 31 | depth_t *depth; 32 | vertex_t *parent; 33 | 34 | csr_graph ggraph; 35 | tdata *gdata; 36 | index_t sml_shed; 37 | index_t lrg_shed; 38 | index_t gpu_id; 39 | index_t *gpu_ranger; 40 | index_t num_agg_bfs; 41 | index_t sw_level; 42 | 43 | int world_sz, my_id; 44 | //constructor 45 | public: 46 | graph() {}; 47 | graph( 48 | graph_reader * g, 49 | index_t sw_level, 50 | index_t vert_count, 51 | index_t edge_count, 52 | index_t num_groups, 53 | index_t num_agg_bfs, 54 | int world_sz, int my_id, 55 | index_t gpu_id, 56 | index_t sml_shed, 57 | index_t lrg_shed); 58 | 59 | //functions 60 | public: 61 | int write_result(); 62 | int bfs_gpu_coalescing_mem(); 63 | int alloc_array(); 64 | 65 | }; 66 | 67 | #include "bfs_gpu_opt.cuh" 68 | #include "graph.cuh" 69 | #include "write_result.cuh" 70 | #include "allocator.cuh" 71 | #endif 72 | //included in main.cpp 73 | // bfs_seq.cpp 74 | // bfs.cu 75 | -------------------------------------------------------------------------------- /graph_reader.cuh: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 The George Washington University 3 | * Written by Hang Liu 4 | * Directed by Prof. Howie Huang 5 | * 6 | * https://www.seas.gwu.edu/~howie/ 7 | * Contact: iheartgraph@gmail.com 8 | * 9 | * 10 | * Please cite the following paper: 11 | * 12 | * Hang Liu, H. Howie Huang and Yang Hu. 2016. iBFS: Concurrent Breadth-First Search on GPUs. Proceedings of the 2016 International Conference on Management of Data. ACM. 13 | * 14 | * This file is part of iBFS. 15 | * 16 | * iBFS is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * iBFS is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with iBFS. If not, see . 28 | */ 29 | 30 | //#include "graph_reader.h" 31 | 32 | inline bool deep_than_two( 33 | vertex_t src, 34 | depth_t *depth, 35 | index_t *beg_pos, 36 | vertex_t *csr 37 | ){ 38 | depth[src]=0; 39 | 40 | //two level DFS 41 | index_t beg=beg_pos[src]; 42 | index_t end=beg_pos[src+1]; 43 | for(;beg. 28 | */ 29 | 30 | #ifndef __GRAPH_READER_H__ 31 | #define __GRAPH_READER_H__ 32 | #include "comm.h" 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include "wtime.h" 38 | #include 39 | #include 40 | #include 41 | 42 | inline off_t fsize(const char *filename) { 43 | struct stat st; 44 | if (stat(filename, &st) == 0) 45 | return st.st_size; 46 | return -1; 47 | } 48 | 49 | 50 | class graph_reader 51 | { 52 | public: 53 | index_t *beg_pos; 54 | vertex_t *csr; 55 | index_t vert_count; 56 | index_t edge_count; 57 | vertex_t *src_list; 58 | index_t src_count; 59 | 60 | public: 61 | graph_reader(){}; 62 | ~graph_reader(){}; 63 | graph_reader(const char *beg_file, 64 | const char *csr_file, 65 | index_t src_count); 66 | 67 | void gen_src(); 68 | void groupby(); 69 | }; 70 | #include "graph_reader.cuh" 71 | #endif 72 | -------------------------------------------------------------------------------- /groupby.cu: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 The George Washington University 3 | * Written by Hang Liu 4 | * Directed by Prof. Howie Huang 5 | * 6 | * https://www.seas.gwu.edu/~howie/ 7 | * Contact: iheartgraph@gmail.com 8 | * 9 | * 10 | * Please cite the following paper: 11 | * 12 | * Hang Liu, H. Howie Huang and Yang Hu. 2016. iBFS: Concurrent Breadth-First Search on GPUs. Proceedings of the 2016 International Conference on Management of Data. ACM. 13 | * 14 | * This file is part of iBFS. 15 | * 16 | * iBFS is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * iBFS is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with iBFS. If not, see . 28 | */ 29 | 30 | #include "util.h" 31 | #include "graph.h" 32 | #include 33 | #include 34 | 35 | 36 | void 37 | graph:: 38 | groupby() 39 | { 40 | vertex_t *new_list = new index_t[src_count]; 41 | index_t *hubmap=new index_t[vert_count]; 42 | index_t *huboff=new index_t[vert_count]; 43 | memset(hubmap,0,sizeof(index_t)*vert_count); 44 | memset(huboff,0,sizeof(index_t)*vert_count); 45 | 46 | //-divide source into connected to hub 47 | //-not connected to half by "remainoff" 48 | /*counting eligible instances*/ 49 | for(index_t i=0;i128) continue; 56 | for(index_t j=beg;j 128) 61 | { 62 | hubmap[csr[j]]++; 63 | break; 64 | } 65 | } 66 | } 67 | 68 | /*prefix-sum counted data*/ 69 | huboff[0]=0; 70 | for(index_t i=1;i128) 85 | { 86 | new_list[remainoff]=src_list[i]; 87 | remainoff++; 88 | test++; 89 | continue; 90 | } 91 | 92 | /*eligible instance*/ 93 | bool isEligible=false; 94 | for(index_t j=beg;j 128) 101 | { 102 | new_list[huboff[csr[j]]]=src_list[i]; 103 | huboff[csr[j]]++; 104 | isEligible=true; 105 | break; 106 | } 107 | } 108 | 109 | if(!isEligible) 110 | { 111 | new_list[remainoff]=src_list[i]; 112 | remainoff++; 113 | test++; 114 | } 115 | } 116 | 117 | #ifdef ENABLE_MONITORING 118 | std::ofstream myfile("origin_src.dat"); 119 | std::ofstream newfile("new_src.dat"); 120 | for(index_t i=0;i 11 | #include 12 | #include 13 | #include "ibfs.h" 14 | 15 | //template 16 | //void proc_desc( 17 | // std::string desc_str, 18 | // std::string &kron_addr, 19 | // index_t &sw_level, 20 | // index_t &vert_count, 21 | // index_t &edge_count 22 | //){ 23 | // //proc desc file 24 | // std::ifstream descfile(desc_str.c_str()); 25 | // std::stringstream ss; 26 | // std::string line; 27 | // index_t count=0; 28 | // 29 | // if(descfile.is_open()){ 30 | // while(std::getline(descfile, line)){ 31 | // count++; 32 | // switch(count){ 33 | // case 5: 34 | // ss.str(""); 35 | // ss.clear(); 36 | // ss<>vert_count;ss>>edge_count;break; 38 | // case 11: 39 | // ss.str(""); 40 | // ss.clear(); 41 | // ss<>kron_addr;ss>>sw_level;break; 43 | // default: 44 | // break; 45 | // } 46 | // } 47 | // }else{std::cout<<"File desc.dat missing\n"; exit(-1);} 48 | // std::cout<<"gpu vert count: "< *graph_d 79 | = new graph 80 | ( 81 | g, 82 | sw_level, 83 | g->vert_count, 84 | g->edge_count, 85 | num_groups, 86 | num_agg_bfs, 87 | world_sz, my_id, 88 | gpu_id, 89 | sml_shed, 90 | lrg_shed); 91 | 92 | // index_t step_sz = graph_d->vert_count/(THDS_NUM*BLKS_NUM); 93 | // if((step_sz%16 != 0)||(graph_d->vert_count%(THDS_NUM*BLKS_NUM))){ 94 | // std::cout<<"Graph vertices sz fails " 95 | // <<"to be exactly divided by thread count\n"; 96 | // return -1; 97 | // } 98 | 99 | std::cout<<"Alloc GPU space\n"; 100 | graph_d->alloc_array(); 101 | std::cout<<"In gpu bfs\n"; 102 | graph_d->bfs_gpu_coalescing_mem(); 103 | // graph_d->write_result(); 104 | return 0; 105 | } 106 | -------------------------------------------------------------------------------- /ibfs.h: -------------------------------------------------------------------------------- 1 | #ifndef IBFSH 2 | #define IBFSH 3 | 4 | typedef int index_t; 5 | int ibfs(int world_sz, int my_id, int gpu_count, int args, char *argv[]); 6 | int reporter(double tm, int my_id, index_t iter); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /inspector.cu: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 The George Washington University 3 | * Written by Hang Liu 4 | * Directed by Prof. Howie Huang 5 | * 6 | * https://www.seas.gwu.edu/~howie/ 7 | * Contact: iheartgraph@gmail.com 8 | * 9 | * 10 | * Please cite the following paper: 11 | * 12 | * Hang Liu, H. Howie Huang and Yang Hu. 2016. iBFS: Concurrent Breadth-First Search on GPUs. Proceedings of the 2016 International Conference on Management of Data. ACM. 13 | * 14 | * This file is part of iBFS. 15 | * 16 | * iBFS is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * iBFS is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with iBFS. If not, see . 28 | */ 29 | 30 | //Dec/15/2013 31 | //Feb/16/2015 32 | //Mar/4/2015 33 | #include "util.h" 34 | #include "gpu_ibfs.cuh" 35 | #include "scan.cuh" 36 | 37 | __global__ void extract_depth( 38 | comp_t *depth_comp_last, 39 | comp_t *depth_comp_curr, 40 | bool *is_done_d, 41 | depth_t curr_level, 42 | index_t vert_count 43 | ){ 44 | 45 | //+- 46 | //|Diff of comp_last and comp_curr = just visited verts 47 | //+-------------------------------------- 48 | 49 | index_t tid=threadIdx.x+blockIdx.x*blockDim.x; 50 | index_t wid=tid>>5; 51 | // const index_t vec_sz=32; 52 | // const index_t LANE=tid%32; 53 | const index_t GRNTY=blockDim.x*gridDim.x; 54 | const index_t WGRNTY=GRNTY>>5; 55 | // const depth_t LEVEL=curr_level; 56 | const index_t COMP_COUNT=vert_count; 57 | comp_t comp_last, comp_curr; 58 | // unsigned int recv_up, recv_low; 59 | bool is_done=true; 60 | 61 | while(tid>32; 71 | // recv_low=change&0xffffffff; 72 | // recv_up=__shfl((int)recv_up,i); 73 | // recv_low=__shfl((int)recv_low,i); 74 | 75 | // if(recv_up&(1<>5; 107 | // const index_t vec_sz=32; 108 | // const index_t LANE=tid%32; 109 | const index_t GRNTY=blockDim.x*gridDim.x; 110 | const index_t WGRNTY=GRNTY>>5; 111 | // const depth_t LEVEL=curr_level; 112 | const index_t COMP_COUNT=vert_count; 113 | comp_t comp_last, comp_curr; 114 | index_t card_curr; 115 | // unsigned int recv_up, recv_low; 116 | 117 | index_t ex_sml_ct= 0; 118 | index_t ex_mid_ct= 0; 119 | index_t ex_lrg_ct= 0; 120 | 121 | while(tid0) 132 | if(card_currlrg_shed) ex_lrg_ct++; 134 | else ex_mid_ct++; 135 | } 136 | 137 | // for(int i=0;i>32; 139 | // recv_low=change&0xffffffff; 140 | // recv_up=__shfl((int)recv_up,i); 141 | // recv_low=__shfl((int)recv_low,i); 142 | 143 | // if(recv_up&(1<= REMAINDER ? REMAINDER:0); 191 | const index_t end_pos=beg_pos+step_sz; 192 | tid=beg_pos; 193 | if(step_sz){ 194 | card_curr = beg_pos_d[beg_pos+1]-beg_pos_d[beg_pos]; 195 | depth_curr = depth_comp_curr[beg_pos]; 196 | // depth_comp_last[beg_pos]=depth_curr; 197 | } 198 | 199 | while(tid0)){ 208 | if(card_currlrg_shed) ex_lrg_ct++; 210 | else ex_mid_ct++; 211 | } 212 | 213 | depth_curr=depth_next; 214 | card_curr = card_next; 215 | } 216 | }else{ 217 | //big problem size 218 | //we want each thread to get 16x indices to check. 219 | if(step_sz&0xf) step_sz=((step_sz>>4)+1)<<4; 220 | if(NUM_VER-step_sz*GRNTY>0) step_sz<<=1; 221 | __shared__ index_t beg_pos_s[THDS_NUM]; 222 | __shared__ depth_t mark_s[THDS_NUM<<4]; 223 | index_t beg_pos_own = step_sz*TID_ST; 224 | beg_pos_s[threadIdx.x] = beg_pos_own; 225 | const index_t TRIES = step_sz>>4; 226 | const index_t lane_id = threadIdx.x%32; 227 | const index_t warp_id = threadIdx.x>>5; 228 | const index_t thread_off= threadIdx.x<<4; 229 | index_t tries = 0; 230 | index_t load_ptr; 231 | index_t proc_vert; 232 | 233 | //+-------------------- 234 | //in shared memory data representation 235 | //--------------------------------------- 236 | // 0000|1111 237 | // |||| 238 | // |||+-------- INFTY ? 239 | // ||+--------- SML ? 240 | // |+---------- MID ? 241 | // +----------- LRG ? 242 | //FURTHER OPTIMIZATION CAN BE CARRIED OUT 243 | //BY PACKING MORE HERE. 244 | //----------------------------------------- 245 | while(tries>4); 249 | depth_curr.x=0;depth_curr.y=0;depth_curr.y=0;depth_curr.w=0; 250 | depth_curr=~depth_curr; 251 | if(proc_vert hub_card[hub_ptr]){ 267 | // hub_vert[hub_ptr] = load_ptr; 268 | // hub_card[hub_ptr] = card_curr; 269 | // } 270 | // }else 271 | if(((~depth_curr)!=0) && (card_curr>0)) 272 | if(card_currlrg_shed) 275 | mark_s[(proc_vert<<4)+(lane_id%16)]=0x09;//1001 276 | else mark_s[(proc_vert<<4)+(lane_id%16)]=0x05;//0101 277 | } 278 | __syncthreads(); 279 | 280 | //thread stride checking 281 | for(int i=0; i<16; i++) 282 | if(mark_s[thread_off+i]&0x02){ 283 | ex_sml_ct++; 284 | }else if(mark_s[thread_off+i]&0x08){ 285 | ex_lrg_ct++; 286 | }else if(mark_s[thread_off+i]&0x04){ 287 | ex_mid_ct++; 288 | } 289 | ++tries; 290 | __syncthreads(); 291 | } 292 | } 293 | 294 | cat_sml_sz_d[TID_ST]= ex_sml_ct; 295 | cat_mid_sz_d[TID_ST]= ex_mid_ct; 296 | cat_lrg_sz_d[TID_ST]= ex_lrg_ct; 297 | } 298 | 299 | __global__ void td_frontier_gather( 300 | index_t *beg_pos_d, 301 | index_t *ex_sml_q_d, 302 | index_t *ex_mid_q_d, 303 | index_t *ex_lrg_q_d, 304 | index_t *cat_sml_off_d, 305 | index_t *cat_mid_off_d, 306 | index_t *cat_lrg_off_d, 307 | comp_t *depth_comp_last, 308 | comp_t *depth_comp_curr, 309 | depth_t curr_level, 310 | index_t vert_count, 311 | const index_t sml_shed, 312 | const index_t lrg_shed 313 | ) 314 | { 315 | index_t TID_ST=threadIdx.x+blockIdx.x*blockDim.x; 316 | index_t tid=TID_ST; 317 | const index_t GRNLTY=blockDim.x*gridDim.x; 318 | const index_t COMP_COUNT=vert_count; 319 | comp_t comp_last, comp_curr; 320 | index_t card_curr; 321 | 322 | index_t ex_sml_ptr = cat_sml_off_d[TID_ST]; 323 | index_t ex_mid_ptr = cat_mid_off_d[TID_ST]; 324 | index_t ex_lrg_ptr = cat_lrg_off_d[TID_ST]; 325 | 326 | while(tid0) 334 | if(card_currlrg_shed) 340 | { 341 | ex_lrg_q_d[ex_lrg_ptr]=tid; 342 | ex_lrg_ptr++; 343 | } 344 | else 345 | { 346 | ex_mid_q_d[ex_mid_ptr]=tid; 347 | ex_mid_ptr++; 348 | } 349 | } 350 | tid+= GRNLTY; 351 | } 352 | } 353 | 354 | 355 | __global__ void sw_frontier_gather( 356 | index_t *beg_pos_d, 357 | index_t *ex_sml_q_d, 358 | index_t *ex_mid_q_d, 359 | index_t *ex_lrg_q_d, 360 | index_t *cat_sml_off_d, 361 | index_t *cat_mid_off_d, 362 | index_t *cat_lrg_off_d, 363 | comp_t *depth_comp_curr, 364 | depth_t curr_level, 365 | index_t vert_count, 366 | const index_t sml_shed, 367 | const index_t lrg_shed 368 | ) 369 | { 370 | const index_t TID_ST = threadIdx.x +blockIdx.x*blockDim.x; 371 | const index_t NUM_VER = vert_count; 372 | const index_t GRNTY = blockDim.x*gridDim.x; 373 | 374 | index_t ex_sml_ptr = cat_sml_off_d[TID_ST]; 375 | index_t ex_mid_ptr = cat_mid_off_d[TID_ST]; 376 | index_t ex_lrg_ptr = cat_lrg_off_d[TID_ST]; 377 | 378 | index_t card_curr, card_next; 379 | comp_t depth_curr,depth_next; 380 | index_t tid,tid_next; 381 | 382 | //Figure out its own start and end pos 383 | //We want each thread to inspect a continuous block 384 | index_t step_sz = NUM_VER/GRNTY; 385 | if(step_sz<16){ 386 | //small problem size 387 | const index_t REMAINDER = NUM_VER-step_sz*GRNTY; 388 | if(TID_ST= REMAINDER ? REMAINDER:0); 391 | const index_t end_pos=beg_pos+step_sz; 392 | 393 | tid=beg_pos;tid_next=beg_pos; 394 | if(step_sz){ 395 | card_curr = beg_pos_d[beg_pos+1]-beg_pos_d[beg_pos]; 396 | depth_curr = depth_comp_curr[beg_pos]; 397 | tid_next++; 398 | } 399 | 400 | while(tid0)&&((~depth_curr)!=0)){ 407 | if(card_currlrg_shed) 413 | { 414 | ex_lrg_q_d[ex_lrg_ptr]=tid; 415 | ex_lrg_ptr++; 416 | } 417 | else 418 | { 419 | ex_mid_q_d[ex_mid_ptr]=tid; 420 | ex_mid_ptr++; 421 | } 422 | } 423 | tid=tid_next; 424 | tid_next++; 425 | card_curr = card_next; 426 | depth_curr=depth_next; 427 | } 428 | }else{ 429 | //big problem size 430 | //We want each thread to get 16x indices to check. 431 | if(step_sz&0xf) step_sz=((step_sz>>4)+1)<<4; 432 | if(NUM_VER-step_sz*GRNTY>0) step_sz<<=1; 433 | __shared__ index_t beg_pos_s[THDS_NUM]; 434 | __shared__ depth_t mark_s[THDS_NUM<<4]; 435 | index_t beg_pos_own = step_sz*TID_ST; 436 | beg_pos_s[threadIdx.x] = beg_pos_own; 437 | const index_t TRIES = step_sz>>4; 438 | const index_t lane_id = threadIdx.x%32; 439 | const index_t warp_id = threadIdx.x>>5; 440 | const index_t thread_off= threadIdx.x<<4; 441 | index_t tries = 0; 442 | index_t load_ptr; 443 | index_t proc_vert; 444 | 445 | //+-------------------- 446 | //in shared memory data representation 447 | //--------------------------------------- 448 | // 0000|1111 449 | // |||| 450 | // |||+-------- INFTY ? 451 | // ||+--------- SML ? 452 | // |+---------- MID ? 453 | // +----------- LRG ? 454 | //FURTHER OPTIMIZATION CAN BE CARRIED OUT 455 | //BY PACKING MORE HERE. 456 | //----------------------------------------- 457 | while(tries>4); 461 | depth_curr.x=0;depth_curr.y=0;depth_curr.y=0;depth_curr.w=0; 462 | depth_curr=~depth_curr; 463 | if(proc_vert0)) 475 | if(card_currlrg_shed) 478 | mark_s[(proc_vert<<4)+(lane_id%16)]=0x09;//1001 479 | else mark_s[(proc_vert<<4)+(lane_id%16)]=0x05;//0101 480 | } 481 | __syncthreads(); 482 | 483 | //thread stride checking 484 | for(int i=0; i<16; i++) 485 | if(mark_s[thread_off+i]&0x02){ 486 | ex_sml_q_d[ex_sml_ptr]=beg_pos_own+(tries<<4)+i; 487 | ex_sml_ptr++; 488 | }else if(mark_s[thread_off+i]&0x08){ 489 | ex_lrg_q_d[ex_lrg_ptr]=beg_pos_own+(tries<<4)+i; 490 | ex_lrg_ptr++; 491 | }else if(mark_s[thread_off+i]&0x04){ 492 | ex_mid_q_d[ex_mid_ptr]=beg_pos_own+(tries<<4)+i; 493 | ex_mid_ptr++; 494 | } 495 | 496 | ++tries; 497 | __syncthreads(); 498 | } 499 | } 500 | } 501 | 502 | 503 | //+-------------------------------------------- 504 | //|CLASSIFIED BASED STORAGE FOR EX_QUEUE 505 | //+--------------------------------------------------- 506 | void 507 | gpu_ibfs:: 508 | td_inspect(depth_t curr_level) 509 | { 510 | td_frontier_count 511 | <<>>( 512 | beg_pos_d, 513 | cat_sml_sz_d, 514 | cat_mid_sz_d, 515 | cat_lrg_sz_d, 516 | depth_comp_last, 517 | depth_comp_curr, 518 | curr_level, 519 | g->vert_count, 520 | sml_shed, 521 | lrg_shed 522 | ); 523 | cudaDeviceSynchronize(); 524 | 525 | insp_scan 526 | ( 527 | cat_sml_sz_d, 528 | cat_sml_off_d, 529 | THDS_NUM*BLKS_NUM, 530 | BLKS_NUM>>1, 531 | THDS_NUM>>1, 532 | ex_sml_sz_d, 533 | stream[0] 534 | ); 535 | insp_scan 536 | ( 537 | cat_mid_sz_d, 538 | cat_mid_off_d, 539 | THDS_NUM*BLKS_NUM, 540 | BLKS_NUM>>1, 541 | THDS_NUM>>1, 542 | ex_mid_sz_d, 543 | stream[1] 544 | ); 545 | insp_scan 546 | ( 547 | cat_lrg_sz_d, 548 | cat_lrg_off_d, 549 | THDS_NUM*BLKS_NUM, 550 | BLKS_NUM>>1, 551 | THDS_NUM>>1, 552 | ex_lrg_sz_d, 553 | stream[2] 554 | ); 555 | 556 | 557 | cudaStreamSynchronize(stream[0]); 558 | cudaStreamSynchronize(stream[1]); 559 | cudaStreamSynchronize(stream[2]); 560 | cudaDeviceSynchronize(); 561 | 562 | td_frontier_gather 563 | <<>>( 564 | beg_pos_d, 565 | ex_sml_q_d, 566 | ex_mid_q_d, 567 | ex_lrg_q_d, 568 | cat_sml_off_d, 569 | cat_mid_off_d, 570 | cat_lrg_off_d, 571 | depth_comp_last, 572 | depth_comp_curr, 573 | curr_level, 574 | g->vert_count, 575 | sml_shed, 576 | lrg_shed 577 | ); 578 | } 579 | 580 | void 581 | gpu_ibfs:: 582 | sw_inspect(depth_t curr_level) 583 | { 584 | is_done[0]=true; 585 | extract_depth 586 | <<>> 587 | ( 588 | depth_comp_last, 589 | depth_comp_curr, 590 | is_done_d, 591 | curr_level, 592 | g->vert_count 593 | ); 594 | 595 | sw_frontier_count 596 | <<>>( 597 | beg_pos_d, 598 | cat_sml_sz_d, 599 | cat_mid_sz_d, 600 | cat_lrg_sz_d, 601 | depth_comp_curr, 602 | curr_level, 603 | g->vert_count, 604 | sml_shed, 605 | lrg_shed 606 | ); 607 | 608 | cudaDeviceSynchronize(); 609 | 610 | insp_scan 611 | ( 612 | cat_sml_sz_d, 613 | cat_sml_off_d, 614 | THDS_NUM*BLKS_NUM, 615 | BLKS_NUM>>1, 616 | THDS_NUM>>1, 617 | ex_sml_sz_d, 618 | stream[0] 619 | ); 620 | insp_scan 621 | ( 622 | cat_mid_sz_d, 623 | cat_mid_off_d, 624 | THDS_NUM*BLKS_NUM, 625 | BLKS_NUM>>1, 626 | THDS_NUM>>1, 627 | ex_mid_sz_d, 628 | stream[1] 629 | ); 630 | insp_scan 631 | ( 632 | cat_lrg_sz_d, 633 | cat_lrg_off_d, 634 | THDS_NUM*BLKS_NUM, 635 | BLKS_NUM>>1, 636 | THDS_NUM>>1, 637 | ex_lrg_sz_d, 638 | stream[2] 639 | ); 640 | 641 | cudaStreamSynchronize(stream[0]); 642 | cudaStreamSynchronize(stream[1]); 643 | cudaStreamSynchronize(stream[2]); 644 | cudaDeviceSynchronize(); 645 | 646 | sw_frontier_gather 647 | <<>>( 648 | beg_pos_d, 649 | ex_sml_q_d, 650 | ex_mid_q_d, 651 | ex_lrg_q_d, 652 | cat_sml_off_d, 653 | cat_mid_off_d, 654 | cat_lrg_off_d, 655 | depth_comp_curr, 656 | curr_level, 657 | g->vert_count, 658 | sml_shed, 659 | lrg_shed 660 | ); 661 | cudaStreamSynchronize(gstream); 662 | } 663 | 664 | void gpu_ibfs:: 665 | inspector(depth_t level) 666 | { 667 | if(level 8 | __global__ void extract_depth( 9 | comp_t *depth_comp_last, 10 | comp_t *depth_comp_curr, 11 | depth_t *depth_merge, 12 | index_t num_agg_bfs, 13 | depth_t curr_level, 14 | index_t vert_count 15 | ){ 16 | 17 | //+- 18 | //|Diff of comp_last and comp_curr = just visited verts 19 | //+-------------------------------------- 20 | index_t tid=threadIdx.x+blockIdx.x*blockDim.x; 21 | index_t wid=tid>>5; 22 | const index_t vec_sz=32; 23 | const index_t LANE=tid%32; 24 | const index_t GRNTY=blockDim.x*gridDim.x; 25 | const index_t WGRNTY=GRNTY>>5; 26 | const depth_t LEVEL=curr_level; 27 | const index_t COMP_COUNT=vert_count; 28 | comp_t comp_last, comp_curr; 29 | // unsigned int recv_up, recv_low; 30 | unsigned int change[4], recv; 31 | 32 | while(tid 63 | __global__ void td_frontier_count 64 | ( 65 | index_t *ex_cat_sml_sz, 66 | index_t *ex_cat_mid_sz, 67 | index_t *ex_cat_lrg_sz, 68 | comp_t *depth_comp_last, 69 | comp_t *depth_comp_curr, 70 | depth_t *depth_merge, 71 | index_t *adj_card_d, 72 | index_t num_agg_bfs, 73 | depth_t curr_level, 74 | index_t vert_count, 75 | const index_t sml_shed, 76 | const index_t lrg_shed 77 | ) 78 | { 79 | //+- 80 | //|Diff of comp_last and comp_curr = just visited verts 81 | //+-------------------------------------- 82 | index_t TID_ST=threadIdx.x+blockIdx.x*blockDim.x; 83 | index_t tid=TID_ST; 84 | index_t wid=TID_ST>>5; 85 | const index_t vec_sz=32; 86 | const index_t LANE=tid%32; 87 | const index_t GRNTY=blockDim.x*gridDim.x; 88 | const index_t WGRNTY=GRNTY>>5; 89 | const depth_t LEVEL=curr_level; 90 | const index_t COMP_COUNT=vert_count; 91 | comp_t comp_last, comp_curr; 92 | index_t card_curr; 93 | unsigned int recv; 94 | 95 | index_t ex_sml_ct= 0; 96 | index_t ex_mid_ct= 0; 97 | index_t ex_lrg_ct= 0; 98 | unsigned int change[4]; 99 | 100 | while(tid0) 124 | if(card_currlrg_shed) ex_lrg_ct++; 126 | else ex_mid_ct++; 127 | } 128 | 129 | __syncthreads(); 130 | tid += GRNTY; 131 | wid += WGRNTY; 132 | } 133 | 134 | ex_cat_sml_sz[TID_ST]= ex_sml_ct; 135 | ex_cat_mid_sz[TID_ST]= ex_mid_ct; 136 | ex_cat_lrg_sz[TID_ST]= ex_lrg_ct; 137 | } 138 | 139 | template 141 | __global__ void sw_frontier_count 142 | ( 143 | index_t *ex_cat_sml_sz, 144 | index_t *ex_cat_mid_sz, 145 | index_t *ex_cat_lrg_sz, 146 | comp_t *depth_comp_curr, 147 | index_t *adj_card_d, 148 | index_t num_agg_bfs, 149 | depth_t curr_level, 150 | index_t vert_count, 151 | const index_t sml_shed, 152 | const index_t lrg_shed 153 | ) 154 | { 155 | const index_t TID_ST = threadIdx.x +blockIdx.x*blockDim.x; 156 | const index_t NUM_VER = vert_count; 157 | const index_t GRNTY = blockDim.x*gridDim.x; 158 | 159 | index_t card_curr,card_next; 160 | comp_t depth_curr,depth_next; 161 | index_t ex_sml_ct = 0; 162 | index_t ex_mid_ct = 0; 163 | index_t ex_lrg_ct = 0; 164 | index_t tid = TID_ST; 165 | 166 | //Figure out its own start and end pos 167 | //We want each thread to inspect a continuous block 168 | index_t step_sz = NUM_VER/GRNTY; 169 | if(step_sz<16){ 170 | //small problem size 171 | const index_t REMAINDER = NUM_VER-step_sz*GRNTY; 172 | if(TID_ST= REMAINDER ? REMAINDER:0); 175 | const index_t end_pos=beg_pos+step_sz; 176 | tid=beg_pos; 177 | if(step_sz){ 178 | card_curr = adj_card_d[beg_pos]; 179 | depth_curr = depth_comp_curr[beg_pos]; 180 | // depth_comp_last[beg_pos]=depth_curr; 181 | } 182 | 183 | while(tid0)&&( 192 | depth_curr.x!=0xffffffff || 193 | depth_curr.y!=0xffffffff || 194 | depth_curr.z!=0xffffffff || 195 | depth_curr.w!=0xffffffff 196 | )){ 197 | if(card_currlrg_shed) ex_lrg_ct++; 199 | else ex_mid_ct++; 200 | } 201 | 202 | depth_curr=depth_next; 203 | card_curr = card_next; 204 | } 205 | }else{ 206 | //big problem size 207 | //we want each thread to get 16x indices to check. 208 | if(step_sz&0xf) step_sz=((step_sz>>4)+1)<<4; 209 | if(NUM_VER-step_sz*GRNTY>0) step_sz<<=1; 210 | __shared__ index_t beg_pos_s[THDS_NUM]; 211 | __shared__ depth_t mark_s[THDS_NUM<<4]; 212 | index_t beg_pos_own = step_sz*TID_ST; 213 | beg_pos_s[threadIdx.x] = beg_pos_own; 214 | const index_t TRIES = step_sz>>4; 215 | const index_t lane_id = threadIdx.x%32; 216 | const index_t warp_id = threadIdx.x>>5; 217 | const index_t thread_off= threadIdx.x<<4; 218 | index_t tries = 0; 219 | index_t load_ptr; 220 | index_t proc_vert; 221 | 222 | //+-------------------- 223 | //in shared memory data representation 224 | //--------------------------------------- 225 | // 0000|1111 226 | // |||| 227 | // |||+-------- INFTY ? 228 | // ||+--------- SML ? 229 | // |+---------- MID ? 230 | // +----------- LRG ? 231 | //FURTHER OPTIMIZATION CAN BE CARRIED OUT 232 | //BY PACKING MORE HERE. 233 | //----------------------------------------- 234 | while(tries>4); 238 | depth_curr.x=0xffffffff; 239 | depth_curr.y=0xffffffff; 240 | depth_curr.z=0xffffffff; 241 | depth_curr.w=0xffffffff; 242 | if(proc_vert hub_card[hub_ptr]){ 258 | // hub_vert[hub_ptr] = load_ptr; 259 | // hub_card[hub_ptr] = card_curr; 260 | // } 261 | // }else 262 | if((card_curr>0) &&( 263 | depth_curr.x!=0xffffffff || 264 | depth_curr.y!=0xffffffff || 265 | depth_curr.z!=0xffffffff || 266 | depth_curr.w!=0xffffffff)) 267 | if(card_currlrg_shed) 270 | mark_s[(proc_vert<<4)+(lane_id%16)]=0x09;//1001 271 | else mark_s[(proc_vert<<4)+(lane_id%16)]=0x05;//0101 272 | } 273 | __syncthreads(); 274 | 275 | //thread stride checking 276 | for(int i=0; i<16; i++) 277 | if(mark_s[thread_off+i]&0x02){ 278 | ex_sml_ct++; 279 | }else if(mark_s[thread_off+i]&0x08){ 280 | ex_lrg_ct++; 281 | }else if(mark_s[thread_off+i]&0x04){ 282 | ex_mid_ct++; 283 | } 284 | ++tries; 285 | __syncthreads(); 286 | } 287 | } 288 | 289 | ex_cat_sml_sz[TID_ST]= ex_sml_ct; 290 | ex_cat_mid_sz[TID_ST]= ex_mid_ct; 291 | ex_cat_lrg_sz[TID_ST]= ex_lrg_ct; 292 | } 293 | 294 | template 296 | __global__ void td_frontier_gather 297 | ( 298 | index_t *ex_sml_q, 299 | index_t *ex_mid_q, 300 | index_t *ex_lrg_q, 301 | index_t *ex_sml_off, 302 | index_t *ex_mid_off, 303 | index_t *ex_lrg_off, 304 | comp_t *depth_comp_last, 305 | comp_t *depth_comp_curr, 306 | depth_t *depth_merge, 307 | index_t *adj_card_d, 308 | index_t num_agg_bfs, 309 | depth_t curr_level, 310 | index_t vert_count, 311 | const index_t sml_shed, 312 | const index_t lrg_shed 313 | ) 314 | { 315 | index_t TID_ST=threadIdx.x+blockIdx.x*blockDim.x; 316 | index_t tid=TID_ST; 317 | const index_t GRNLTY=blockDim.x*gridDim.x; 318 | const index_t COMP_COUNT=vert_count; 319 | comp_t comp_last, comp_curr; 320 | index_t card_curr; 321 | 322 | index_t ex_sml_ptr = ex_sml_off[TID_ST]; 323 | index_t ex_mid_ptr = ex_mid_off[TID_ST]; 324 | index_t ex_lrg_ptr = ex_lrg_off[TID_ST]; 325 | unsigned int change[4]; 326 | 327 | 328 | while(tid0) 344 | if(card_currlrg_shed) 350 | { 351 | ex_lrg_q[ex_lrg_ptr]=tid; 352 | ex_lrg_ptr++; 353 | } 354 | else 355 | { 356 | ex_mid_q[ex_mid_ptr]=tid; 357 | ex_mid_ptr++; 358 | } 359 | } 360 | tid+= GRNLTY; 361 | } 362 | } 363 | 364 | 365 | template 367 | __global__ void sw_frontier_gather 368 | ( 369 | index_t *ex_sml_q, 370 | index_t *ex_mid_q, 371 | index_t *ex_lrg_q, 372 | index_t *ex_sml_off, 373 | index_t *ex_mid_off, 374 | index_t *ex_lrg_off, 375 | comp_t *depth_comp_curr, 376 | index_t *adj_card_d, 377 | index_t num_agg_bfs, 378 | depth_t curr_level, 379 | index_t vert_count, 380 | const index_t sml_shed, 381 | const index_t lrg_shed 382 | ) 383 | { 384 | const index_t TID_ST = threadIdx.x +blockIdx.x*blockDim.x; 385 | const index_t NUM_VER = vert_count; 386 | const index_t GRNTY = blockDim.x*gridDim.x; 387 | 388 | index_t ex_sml_ptr = ex_sml_off[TID_ST]; 389 | index_t ex_mid_ptr = ex_mid_off[TID_ST]; 390 | index_t ex_lrg_ptr = ex_lrg_off[TID_ST]; 391 | 392 | index_t card_curr, card_next; 393 | comp_t depth_curr,depth_next; 394 | index_t tid,tid_next; 395 | 396 | //Figure out its own start and end pos 397 | //We want each thread to inspect a continuous block 398 | index_t step_sz = NUM_VER/GRNTY; 399 | if(step_sz<16){ 400 | //small problem size 401 | const index_t REMAINDER = NUM_VER-step_sz*GRNTY; 402 | if(TID_ST= REMAINDER ? REMAINDER:0); 405 | const index_t end_pos=beg_pos+step_sz; 406 | 407 | tid=beg_pos;tid_next=beg_pos; 408 | if(step_sz){ 409 | card_curr = adj_card_d[beg_pos]; 410 | depth_curr = depth_comp_curr[beg_pos]; 411 | tid_next++; 412 | } 413 | 414 | while(tid0)&&( 421 | depth_curr.x!=0xffffffff || 422 | depth_curr.y!=0xffffffff || 423 | depth_curr.z!=0xffffffff || 424 | depth_curr.w!=0xffffffff 425 | )){ 426 | if(card_currlrg_shed) 432 | { 433 | ex_lrg_q[ex_lrg_ptr]=tid; 434 | ex_lrg_ptr++; 435 | } 436 | else 437 | { 438 | ex_mid_q[ex_mid_ptr]=tid; 439 | ex_mid_ptr++; 440 | } 441 | } 442 | tid=tid_next; 443 | tid_next++; 444 | card_curr = card_next; 445 | depth_curr=depth_next; 446 | } 447 | }else{ 448 | //big problem size 449 | //We want each thread to get 16x indices to check. 450 | if(step_sz&0xf) step_sz=((step_sz>>4)+1)<<4; 451 | if(NUM_VER-step_sz*GRNTY>0) step_sz<<=1; 452 | __shared__ index_t beg_pos_s[THDS_NUM]; 453 | __shared__ depth_t mark_s[THDS_NUM<<4]; 454 | index_t beg_pos_own = step_sz*TID_ST; 455 | beg_pos_s[threadIdx.x] = beg_pos_own; 456 | const index_t TRIES = step_sz>>4; 457 | const index_t lane_id = threadIdx.x%32; 458 | const index_t warp_id = threadIdx.x>>5; 459 | const index_t thread_off= threadIdx.x<<4; 460 | index_t tries = 0; 461 | index_t load_ptr; 462 | index_t proc_vert; 463 | 464 | //+-------------------- 465 | //in shared memory data representation 466 | //--------------------------------------- 467 | // 0000|1111 468 | // |||| 469 | // |||+-------- INFTY ? 470 | // ||+--------- SML ? 471 | // |+---------- MID ? 472 | // +----------- LRG ? 473 | //FURTHER OPTIMIZATION CAN BE CARRIED OUT 474 | //BY PACKING MORE HERE. 475 | //----------------------------------------- 476 | while(tries>4); 480 | depth_curr.x=0xffffffff; 481 | depth_curr.y=0xffffffff; 482 | depth_curr.z=0xffffffff; 483 | depth_curr.w=0xffffffff; 484 | if(proc_vert0) &&( 496 | depth_curr.x!=0xffffffff || 497 | depth_curr.y!=0xffffffff || 498 | depth_curr.z!=0xffffffff || 499 | depth_curr.w!=0xffffffff)) 500 | if(card_currlrg_shed) 503 | mark_s[(proc_vert<<4)+(lane_id%16)]=0x09;//1001 504 | else mark_s[(proc_vert<<4)+(lane_id%16)]=0x05;//0101 505 | } 506 | __syncthreads(); 507 | 508 | //thread stride checking 509 | for(int i=0; i<16; i++) 510 | if(mark_s[thread_off+i]&0x02){ 511 | ex_sml_q[ex_sml_ptr]=beg_pos_own+(tries<<4)+i; 512 | ex_sml_ptr++; 513 | }else if(mark_s[thread_off+i]&0x08){ 514 | ex_lrg_q[ex_lrg_ptr]=beg_pos_own+(tries<<4)+i; 515 | ex_lrg_ptr++; 516 | }else if(mark_s[thread_off+i]&0x04){ 517 | ex_mid_q[ex_mid_ptr]=beg_pos_own+(tries<<4)+i; 518 | ex_mid_ptr++; 519 | } 520 | 521 | ++tries; 522 | __syncthreads(); 523 | } 524 | } 525 | } 526 | 527 | 528 | //+-------------------------------------------- 529 | //|CLASSIFIED BASED STORAGE FOR EX_QUEUE 530 | //+--------------------------------------------------- 531 | template< typename vertex_t, 532 | typename index_t, 533 | typename depth_t> 534 | void td_inspect 535 | ( 536 | tdata *gdata, 537 | csr_graph ggraph, 538 | index_t num_agg_bfs, 539 | index_t sw_level, 540 | depth_t curr_level, 541 | index_t vert_count,//num ver in the graph 542 | const index_t sml_shed, 543 | const index_t lrg_shed 544 | ) 545 | { 546 | td_frontier_count 547 | 548 | <<>> 549 | ( 550 | ggraph->ex_cat_sml_sz, 551 | ggraph->ex_cat_mid_sz, 552 | ggraph->ex_cat_lrg_sz, 553 | ggraph->depth_comp_last, 554 | ggraph->depth_comp_curr, 555 | ggraph->depth_merge, 556 | ggraph->adj_card_d, 557 | num_agg_bfs, 558 | curr_level, 559 | vert_count, 560 | sml_shed, 561 | lrg_shed 562 | ); 563 | cudaDeviceSynchronize(); 564 | 565 | insp_scan 566 | 567 | ( 568 | ggraph->ex_cat_sml_sz, 569 | ggraph->ex_sml_off, 570 | THDS_NUM*BLKS_NUM, 571 | BLKS_NUM>>1, 572 | THDS_NUM>>1, 573 | gdata[0]->ex_sml_sz_d, 574 | gdata[0]->stream[0] 575 | ); 576 | insp_scan 577 | 578 | ( 579 | ggraph->ex_cat_mid_sz, 580 | ggraph->ex_mid_off, 581 | THDS_NUM*BLKS_NUM, 582 | BLKS_NUM>>1, 583 | THDS_NUM>>1, 584 | gdata[0]->ex_mid_sz_d, 585 | gdata[0]->stream[1] 586 | ); 587 | insp_scan 588 | 589 | ( 590 | ggraph->ex_cat_lrg_sz, 591 | ggraph->ex_lrg_off, 592 | THDS_NUM*BLKS_NUM, 593 | BLKS_NUM>>1, 594 | THDS_NUM>>1, 595 | gdata[0]->ex_lrg_sz_d, 596 | gdata[0]->stream[2] 597 | ); 598 | 599 | 600 | cudaStreamSynchronize(gdata[0]->stream[0]); 601 | cudaStreamSynchronize(gdata[0]->stream[1]); 602 | cudaStreamSynchronize(gdata[0]->stream[2]); 603 | cudaDeviceSynchronize(); 604 | 605 | td_frontier_gather 606 | 607 | <<>> 608 | ( 609 | ggraph->ex_sml_q, 610 | ggraph->ex_mid_q, 611 | ggraph->ex_lrg_q, 612 | ggraph->ex_sml_off, 613 | ggraph->ex_mid_off, 614 | ggraph->ex_lrg_off, 615 | ggraph->depth_comp_last, 616 | ggraph->depth_comp_curr, 617 | ggraph->depth_merge, 618 | ggraph->adj_card_d, 619 | num_agg_bfs, 620 | curr_level, 621 | vert_count, 622 | sml_shed, 623 | lrg_shed 624 | ); 625 | 626 | } 627 | 628 | template< typename vertex_t, 629 | typename index_t, 630 | typename depth_t> 631 | void sw_inspect 632 | ( 633 | tdata *gdata, 634 | csr_graph ggraph, 635 | index_t num_agg_bfs, 636 | depth_t curr_level, 637 | index_t vert_count,//num ver in the graph 638 | const index_t sml_shed, 639 | const index_t lrg_shed 640 | ) 641 | { 642 | ENABLE_BTUP=true; 643 | extract_depth 644 | 645 | <<gstream>>> 646 | ( 647 | ggraph->depth_comp_last, 648 | ggraph->depth_comp_curr, 649 | ggraph->depth_merge, 650 | num_agg_bfs, 651 | curr_level, 652 | vert_count 653 | ); 654 | 655 | //ONLY COMPRESS ONE TIME 656 | // if(ENABLE_BTUP==false){ 657 | // ENABLE_BTUP=true; 658 | // comp_depth 659 | // 660 | // <<>> 661 | // ( 662 | // ggraph->depth_merge, 663 | // ggraph->depth_comp_last, 664 | // ggraph->depth_comp_curr, 665 | // curr_level, 666 | // 0, 667 | // vert_count 668 | // ); 669 | // cudaDeviceSynchronize(); 670 | // } 671 | 672 | sw_frontier_count 673 | 674 | <<>> 675 | ( 676 | ggraph->ex_cat_sml_sz, 677 | ggraph->ex_cat_mid_sz, 678 | ggraph->ex_cat_lrg_sz, 679 | ggraph->depth_comp_curr, 680 | ggraph->adj_card_d, 681 | num_agg_bfs, 682 | curr_level, 683 | vert_count, 684 | sml_shed, 685 | lrg_shed 686 | ); 687 | 688 | cudaDeviceSynchronize(); 689 | 690 | insp_scan 691 | 692 | ( 693 | ggraph->ex_cat_sml_sz, 694 | ggraph->ex_sml_off, 695 | THDS_NUM*BLKS_NUM, 696 | BLKS_NUM>>1, 697 | THDS_NUM>>1, 698 | gdata[0]->ex_sml_sz_d, 699 | gdata[0]->stream[0] 700 | ); 701 | insp_scan 702 | 703 | ( 704 | ggraph->ex_cat_mid_sz, 705 | ggraph->ex_mid_off, 706 | THDS_NUM*BLKS_NUM, 707 | BLKS_NUM>>1, 708 | THDS_NUM>>1, 709 | gdata[0]->ex_mid_sz_d, 710 | gdata[0]->stream[1] 711 | ); 712 | insp_scan 713 | 714 | ( 715 | ggraph->ex_cat_lrg_sz, 716 | ggraph->ex_lrg_off, 717 | THDS_NUM*BLKS_NUM, 718 | BLKS_NUM>>1, 719 | THDS_NUM>>1, 720 | gdata[0]->ex_lrg_sz_d, 721 | gdata[0]->stream[2] 722 | ); 723 | 724 | 725 | cudaStreamSynchronize(gdata[0]->stream[0]); 726 | cudaStreamSynchronize(gdata[0]->stream[1]); 727 | cudaStreamSynchronize(gdata[0]->stream[2]); 728 | cudaDeviceSynchronize(); 729 | 730 | sw_frontier_gather 731 | 732 | <<>> 733 | ( 734 | ggraph->ex_sml_q, 735 | ggraph->ex_mid_q, 736 | ggraph->ex_lrg_q, 737 | ggraph->ex_sml_off, 738 | ggraph->ex_mid_off, 739 | ggraph->ex_lrg_off, 740 | ggraph->depth_comp_curr, 741 | ggraph->adj_card_d, 742 | num_agg_bfs, 743 | curr_level, 744 | vert_count, 745 | sml_shed, 746 | lrg_shed 747 | ); 748 | cudaStreamSynchronize(ggraph->gstream); 749 | } 750 | 751 | 752 | template 756 | void inspector 757 | ( 758 | tdata *gdata, 759 | csr_graph ggraph, 760 | index_t num_agg_bfs, 761 | index_t sw_level, 762 | depth_t level, 763 | index_t vert_count, 764 | const index_t sml_shed, 765 | const index_t lrg_shed 766 | ) 767 | { 768 | // comp_t *d_status_curr,*d_status_last; 769 | // cudaMallocHost((void **)&d_status_curr, sizeof(comp_t)*vert_count); 770 | // cudaMallocHost((void **)&d_status_last, sizeof(comp_t)*vert_count); 771 | // cudaMemcpy(d_status_curr, ggraph->depth_comp_curr,sizeof(comp_t)*vert_count,cudaMemcpyDeviceToHost); 772 | // cudaMemcpy(d_status_last, ggraph->depth_comp_last,sizeof(comp_t)*vert_count,cudaMemcpyDeviceToHost); 773 | // 774 | // int ft_count=0; int diff=0; 775 | // for(int i=0;iadj_card[i]>0) ft_count++; 778 | // } 779 | // std::cout<<"ft_count-diff "< 787 | ( 788 | gdata, 789 | ggraph, 790 | num_agg_bfs, 791 | sw_level, 792 | level, 793 | vert_count, 794 | sml_shed, 795 | lrg_shed 796 | ); 797 | else{ 798 | 799 | sw_inspect 800 | 801 | ( 802 | gdata, 803 | ggraph, 804 | num_agg_bfs, 805 | level, 806 | vert_count, 807 | sml_shed, 808 | lrg_shed 809 | ); 810 | } 811 | } 812 | -------------------------------------------------------------------------------- /launch.bash: -------------------------------------------------------------------------------- 1 | #declare -a name=(fb ok kg1 rd hw tw pk wk) 2 | declare -a name=(rm) 3 | 4 | for ((gcount=1;gcount<=32;gcount=gcount*2)) 5 | do 6 | for file in ${name[@]} 7 | do 8 | file_inst=jobScript"$gcount"gpu-$file 9 | if [ -f $file_inst ] 10 | then 11 | sbatch $file_inst 12 | fi 13 | done 14 | done 15 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "ibfs.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #define USE_GPU_ID 4 7 | int main(int args, char *argv[]) { 8 | 9 | MPI_Init(&args,&argv); 10 | int world_sz; 11 | MPI_Comm_size(MPI_COMM_WORLD, &world_sz); 12 | 13 | int my_id; 14 | MPI_Comm_rank(MPI_COMM_WORLD, &my_id); 15 | const index_t gpu_id = USE_GPU_ID; 16 | ibfs(world_sz, my_id, gpu_id, args, argv); 17 | 18 | MPI_Finalize(); 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /main.cu: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 The George Washington University 3 | * Written by Hang Liu 4 | * Directed by Prof. Howie Huang 5 | * 6 | * https://www.seas.gwu.edu/~howie/ 7 | * Contact: iheartgraph@gmail.com 8 | * 9 | * 10 | * Please cite the following paper: 11 | * 12 | * Hang Liu, H. Howie Huang and Yang Hu. 2016. iBFS: Concurrent Breadth-First Search on GPUs. Proceedings of the 2016 International Conference on Management of Data. ACM. 13 | * 14 | * This file is part of iBFS. 15 | * 16 | * iBFS is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * iBFS is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with iBFS. If not, see . 28 | */ 29 | 30 | #include "gpu_ibfs.cuh" 31 | #include "graph.h" 32 | #include 33 | #include 34 | #include 35 | 36 | int main(int args, char *argv[]) { 37 | typedef long vertex_t; 38 | typedef long index_t; 39 | typedef unsigned char depth_t; 40 | typedef unsigned long long int comp_t; 41 | std::cout<<"Input: /path/to/exe /path/to/beg " 42 | <<"/path/to/csr concurrent-count " 43 | <<"switch-level bfs_count\n"; 44 | if(args != 6){std::cout<<"Wrong input\n";exit(-1);} 45 | 46 | const char *beg_file=argv[1]; 47 | const char *csr_file=argv[2]; 48 | const int concurr_count=atoi(argv[3]); 49 | const depth_t sw_level=atoi(argv[4]); 50 | const index_t src_count=atoi(argv[5]); 51 | graph *g=new graph(beg_file, csr_file, src_count); 52 | g->gen_src(); 53 | g->groupby(); 54 | 55 | cudaSetDeviceFlags(cudaDeviceMapHost); 56 | const index_t sml_shed = 32; 57 | const index_t lrg_shed = 512; 58 | index_t gpu_count = 1; 59 | 60 | gpu_ibfs *ibfs_inst = new gpu_ibfs 61 | ((const graph *)g, 62 | concurr_count, 63 | sw_level, 64 | gpu_count, 65 | sml_shed, 66 | lrg_shed); 67 | 68 | 69 | //keep track of orphans 70 | comp_t *tmp_depth; 71 | H_ERR(cudaMallocHost((void **)&tmp_depth, 72 | sizeof(comp_t)*g->vert_count*ibfs_inst->joint_count)); 73 | 74 | std::cout<<"Start bfs ...\n"; 75 | double tm_ibfs=wtime(); 76 | for(index_t i=0; idepth_comp_last,tmp_depth, 80 | sizeof(comp_t)*g->vert_count*ibfs_inst->joint_count, 81 | cudaMemcpyHostToDevice); 82 | cudaMemcpy(ibfs_inst->depth_comp_curr,tmp_depth, 83 | sizeof(comp_t)*g->vert_count*ibfs_inst->joint_count, 84 | cudaMemcpyHostToDevice); 85 | 86 | double tm_ibfs=wtime(); 87 | ibfs_inst->traversal(grp_beg); 88 | std::cout<<"Traversal-time: "<write_result(); 90 | } 91 | std::cout<<"Total time: "<$2)fq=$2}END{print fq}') 13 | # array[$i]=$(grep -E "Break-fq-sz: $fqsz|Traversal-" $name-diff-outdegree-"$share".log | grep -A 1 Break | sed -e "/--/d;/Break/d" | awk -F " " -v count=0 -v time=0 '{time+=$2;count++}END{print time/count}') 14 | # i=$((i+1)) 15 | # done 16 | # printf "%s," "$name" 17 | # printf "%s," "${array[@]}" 18 | # echo 19 | #done 20 | 21 | 22 | 23 | echo "#Share same hub" 24 | for name in ${file[@]} 25 | do 26 | #echo $name 27 | i=1 28 | for ((num_groups=1;num_groups<=1048576;num_groups=num_groups*2)) 29 | #for share in 16 30 | #for num_groups in 1 2 3 4 5 6 7 8 9 10 50 100 200 300 400 500 600 700 800 900 1000 31 | do 32 | fqsz=$(grep "Break-fq-sz" "$name"."$num_groups".nogroupby.log | awk -F " " -v fq=10000000 '{if(fq>$2)fq=$2}END{print fq}') 33 | array[$i]=$(grep -E "Break-fq-sz: $fqsz|Traversal-" "$name"."$num_groups".nogroupby.log | grep -A 1 Break | sed -e "/--/d;/Break/d" | awk -F " " -v count=0 -v time=0 '{time+=$2;count++}END{if(count!=0){print time/count}}') 34 | i=$((i+1)) 35 | done 36 | printf "%s\n" "$name" 37 | printf "%s\n" "${array[@]}" 38 | echo 39 | done 40 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ---- 2 | Software requirement 3 | ----- 4 | gcc 4.4.7 or 4.8.5 5 | 6 | CUDA 5.5, 6.0, 6.5, 7.0, 7.5 (tested and works) 7 | 8 | MPI: MPICH version 3.3 or higher, corresponding OpenMPI should also work 9 | 10 | 11 | ---- 12 | Hardware 13 | ------ 14 | GPU: C2050, C2070, K20, K40 (tested) 15 | 16 | ---- 17 | Compile 18 | ----- 19 | 20 | make 21 | 22 | ---- 23 | Execute 24 | ------ 25 | Type: "./gpu_ibfs.bin" it will show you what is needed. 26 | 27 | **Atention**, please make *concurrent-count* as **128** 28 | 29 | You could use the code from "tuple_text_to_binary_csr" folder to convert a edge list (text formated) graph into CSR files (binary), e.g., if you have a text file called "test.txt", it will convert it into "test.txt_beg_pos.bin" and "test.txt_csr.bin". You will need these two files to run gpu_ibfs. 30 | 31 | ---- 32 | Converter: edge tuples to CSR 33 | ---- 34 | - Compile: make 35 | - To execute: type "./text_to_bin", it will show you what is needed 36 | - Basically, you could download a tuple list file from [snap](https://snap.stanford.edu/data/). Afterwards, you could use this converter to convert the edge list into CSR format. 37 | 38 | **For example**: 39 | 40 | - Download https://snap.stanford.edu/data/com-Orkut.html file. **unzip** it. 41 | - **./text_to_bin.bin soc-orkut.mtx 1 2(the number may change due to how many lines are not edges)** 42 | - You will get *soc-orkut.mtx_beg_pos.bin* and *soc-orkut.mtx_csr.bin*. 43 | - You could use these two files to run enterprise. 44 | 45 | ---- 46 | Applications of iBFS 47 | --------- 48 | - Centrality computation, e.g., Betweenness centrality, Closeness centrality. 49 | - Multi-source shortest path, All-pairs shortest path. 50 | - Reachiability index construction. 51 | - **In short, any applications, which need to run multiple traversals on the same graph, should benefit** 52 | 53 | ---- 54 | Reference 55 | ------- 56 | 57 | [SC '15] Enterprise: Breadth-First Graph Traversal on GPUs [[PDF](http://hang-liu.com/publication/enterprise_sc15.pdf)] [[Slides](http://hang-liu.com/publication/enterprise_slides.pdf)] [[Blog](http://hang-liu.com/enterprise_blog.html)] 58 | 59 | [SIGMOD '16] iBFS: Concurrent Breadth-First Search on GPUs [[PDF](http://hang-liu.com/publication/ibfs.pdf)] [[Slides](http://hang-liu.com/publication/ibfs_slides.pdf)] [[Poster](http://hang-liu.com/publication/ibfs_poster.pdf)] 60 | -------------------------------------------------------------------------------- /reporter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "ibfs.h" 3 | #include 4 | 5 | int reporter(double tm, int my_id, index_t iter) 6 | { 7 | MPI_Barrier(MPI_COMM_WORLD); 8 | double max_tm; 9 | MPI_Reduce(&tm, &max_tm, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); 10 | if(my_id==0)std::cout<<"Traversal-iter-"<>LOG_NUM_BANKS) 7 | 8 | //USED FOR EXPANSION 9 | //template 10 | //__global__ void __pre_scan( 11 | // data_t *scan_ind_d, 12 | // data_t *adj_card_d, 13 | // data_t *scan_out_d, 14 | // data_t *blk_sum, 15 | // index_t num_dat, 16 | // const index_t THD_NUM 17 | // ) 18 | //{ 19 | // const data_t tile_sz = THD_NUM<<1; 20 | // const index_t lane = threadIdx.x<<1; 21 | // index_t tid = threadIdx.x+blockIdx.x*blockDim.x; 22 | // index_t proc_tile = blockIdx.x; 23 | // 24 | // index_t offset = 1; 25 | // index_t tid_strip; 26 | // index_t idct_a, idct_b; 27 | // const index_t padding = CONFLICT_FREE_OFFSET(tile_sz - 1); 28 | // const index_t NUM_THS = gridDim.x*blockDim.x; 29 | // 30 | // //conflict free 31 | // const index_t off_a = CONFLICT_FREE_OFFSET(lane); 32 | // const index_t off_b = CONFLICT_FREE_OFFSET(lane+1); 33 | // index_t num_tiles = num_dat/tile_sz; 34 | // if(num_dat%tile_sz) 35 | // num_tiles++; 36 | // 37 | // //prefetching danger 38 | // extern __shared__ data_t s_mem[]; 39 | // //__shared__ data_t s_mem[280]; 40 | // 41 | // while(proc_tile < num_tiles) 42 | // { 43 | // tid_strip = tid<<1; 44 | // if(tid_strip < num_dat) 45 | // { 46 | // idct_a = scan_ind_d[tid_strip]; 47 | // s_mem[lane+off_a]= adj_card_d[idct_a]; 48 | // }else{ 49 | // s_mem[lane+off_a]= 0; 50 | // } 51 | // 52 | // if((tid_strip + 1) < num_dat) 53 | // { 54 | // idct_b = scan_ind_d[tid_strip + 1]; 55 | // s_mem[lane + 1 + off_b] = adj_card_d[idct_b]; 56 | // }else{ 57 | // s_mem[lane + 1 + off_b] = 0; 58 | // } 59 | // __syncthreads(); 60 | // 61 | // //up sweep 62 | // for(index_t j = THD_NUM;j > 0;j>>=1) 63 | // { 64 | // if(threadIdx.x < j) 65 | // { 66 | // index_t ai = offset*lane +offset - 1; 67 | // index_t bi = ai + offset; 68 | // ai += CONFLICT_FREE_OFFSET(ai); 69 | // bi += CONFLICT_FREE_OFFSET(bi); 70 | // s_mem[bi] += s_mem[ai]; 71 | // } 72 | // offset <<=1; 73 | // __syncthreads(); 74 | // } 75 | // __syncthreads(); 76 | // 77 | // //write the block sum 78 | // if(blockDim.x > 1)//save sml scan job 79 | // { 80 | // if(threadIdx.x == 0) 81 | // { 82 | // blk_sum[tid/THD_NUM] = 83 | // s_mem[tile_sz -1 + padding]; 84 | // s_mem[tile_sz-1 + padding] = 0; 85 | // } 86 | // __syncthreads(); 87 | // } 88 | // 89 | // //down sweep 90 | // for(index_t j=1; j < tile_sz; j <<=1) 91 | // { 92 | // offset >>= 1; 93 | // if(threadIdx.x < j) 94 | // { 95 | // index_t ai = lane*offset + offset - 1; 96 | // index_t bi = ai + offset; 97 | // ai += CONFLICT_FREE_OFFSET(ai); 98 | // bi += CONFLICT_FREE_OFFSET(bi); 99 | // index_t t = s_mem[ai]; 100 | // s_mem[ai] = s_mem[bi]; 101 | // s_mem[bi] += t; 102 | // } 103 | // __syncthreads(); 104 | // } 105 | // __syncthreads(); 106 | // 107 | // //store data 108 | // if(tid_strip < num_dat) 109 | // { 110 | // scan_out_d[tid_strip] = s_mem[lane+off_a]; 111 | // } 112 | // 113 | // if((tid_strip + 1) < num_dat) 114 | // { 115 | // scan_out_d[tid_strip+1] = s_mem[lane+1+off_b]; 116 | // } 117 | // 118 | // tid += NUM_THS; 119 | // proc_tile += gridDim.x; 120 | // } 121 | //} 122 | // 123 | ////USED FOR lrg_scan 124 | //template 125 | //__global__ void __spine_scan( 126 | // data_t *blk_sum, 127 | // data_t *grd_sum, 128 | // index_t num_dat, 129 | // const index_t THD_NUM 130 | // ) 131 | //{ 132 | // extern __shared__ data_t s_mem[]; 133 | // 134 | // const data_t tile_sz = THD_NUM<<1; 135 | // const index_t lane = threadIdx.x<<1; 136 | // const index_t GRNTY= blockDim.x*gridDim.x; 137 | // 138 | // const index_t padding = CONFLICT_FREE_OFFSET(tile_sz - 1); 139 | // const index_t off_a = CONFLICT_FREE_OFFSET(lane); 140 | // const index_t off_b = CONFLICT_FREE_OFFSET(lane+1); 141 | // 142 | // index_t tid = threadIdx.x+blockIdx.x*blockDim.x; 143 | // index_t offset = 1; 144 | // index_t tid_strip = tid<<1; 145 | // index_t proc_tile = blockIdx.x; 146 | // 147 | // index_t num_tiles = num_dat/tile_sz; 148 | // if(num_dat%tile_sz) 149 | // num_tiles++; 150 | // 151 | // while(proc_tile < num_tiles) 152 | // { 153 | // tid_strip = tid<<1; 154 | // 155 | // if(tid_strip < num_dat) 156 | // s_mem[lane+off_a] = blk_sum[tid_strip]; 157 | // else 158 | // s_mem[lane+off_a] = 0; 159 | // 160 | // if(tid_strip < num_dat) 161 | // s_mem[lane+1+off_b] = blk_sum[tid_strip + 1]; 162 | // else 163 | // s_mem[lane+1+off_b] = 0; 164 | // 165 | // __syncthreads(); 166 | // 167 | // //up sweep 168 | // for(index_t j = THD_NUM;j > 0;j>>=1) 169 | // { 170 | // if(threadIdx.x < j) 171 | // { 172 | // index_t ai = offset*lane +offset - 1; 173 | // index_t bi = ai + offset; 174 | // 175 | // ai += CONFLICT_FREE_OFFSET(ai); 176 | // bi += CONFLICT_FREE_OFFSET(bi); 177 | // s_mem[bi] += s_mem[ai]; 178 | // } 179 | // offset <<=1; 180 | // __syncthreads(); 181 | // } 182 | // __syncthreads(); 183 | // 184 | // //write the block sum 185 | // if(threadIdx.x == 0) 186 | // { 187 | // grd_sum[tid/THD_NUM]= 188 | // s_mem[tile_sz-1+padding]; 189 | // s_mem[tile_sz-1+padding]= 0; 190 | // } 191 | // __syncthreads(); 192 | // 193 | // //down sweep 194 | // for(index_t j=1; j < tile_sz; j <<=1) 195 | // { 196 | // offset >>= 1; 197 | // if(threadIdx.x < j) 198 | // { 199 | // index_t ai = lane*offset + offset - 1; 200 | // index_t bi = ai + offset; 201 | // ai += CONFLICT_FREE_OFFSET(ai); 202 | // bi += CONFLICT_FREE_OFFSET(bi); 203 | // index_t t = s_mem[ai]; 204 | // s_mem[ai] = s_mem[bi]; 205 | // s_mem[bi] += t; 206 | // } 207 | // __syncthreads(); 208 | // } 209 | // __syncthreads(); 210 | // if(tid_strip < num_dat) 211 | // blk_sum[tid_strip] = s_mem[lane+off_a]; 212 | // if(tid_strip + 1< num_dat) 213 | // blk_sum[tid_strip+1] = s_mem[lane+1+off_b]; 214 | // 215 | // tid += GRNTY; 216 | // proc_tile += gridDim.x; 217 | // } 218 | //} 219 | // 220 | /////////////////////////////////////////////////////// 221 | ////post_scan for large problem 222 | //////////////////////////////////////////////////////// 223 | //template 224 | //__global__ void __post_scan( 225 | // data_t *scan_out_d, 226 | // data_t *blk_sum, 227 | // data_t *grd_sum, 228 | // index_t num_dat, 229 | // index_t num_grd, 230 | // const index_t THD_NUM 231 | // ) 232 | //{ 233 | // extern __shared__ data_t s_mem[]; 234 | // 235 | // const data_t tile_sz = THD_NUM<<1; 236 | // const index_t lane = threadIdx.x<<1; 237 | // index_t tid = threadIdx.x+blockIdx.x*blockDim.x; 238 | // index_t offset = 1; 239 | // 240 | // const index_t padding = CONFLICT_FREE_OFFSET(tile_sz - 1); 241 | // 242 | // const index_t off_a = CONFLICT_FREE_OFFSET(lane); 243 | // const index_t off_b = CONFLICT_FREE_OFFSET(lane+1); 244 | // ///////////////////////////////////////////////////////// 245 | // //GRID SCAN 246 | // ///////////////////////////////////////////////////////// 247 | // if(lane < num_grd) 248 | // s_mem[lane+off_a]=grd_sum[lane]; 249 | // else 250 | // s_mem[lane+off_a]=0; 251 | // 252 | // if(lane+1 < num_grd) 253 | // s_mem[lane+1+off_b]=grd_sum[lane+1]; 254 | // else 255 | // s_mem[lane+1+off_b]=0; 256 | // 257 | // __syncthreads(); 258 | // 259 | // //up sweep 260 | // for(index_t j = THD_NUM;j > 0;j>>=1) 261 | // { 262 | // if(threadIdx.x < j) 263 | // { 264 | // index_t ai = offset*lane +offset - 1; 265 | // index_t bi = ai + offset; 266 | // 267 | // ai += CONFLICT_FREE_OFFSET(ai); 268 | // bi += CONFLICT_FREE_OFFSET(bi); 269 | // s_mem[bi] += s_mem[ai]; 270 | // } 271 | // offset <<=1; 272 | // __syncthreads(); 273 | // } 274 | // __syncthreads(); 275 | // 276 | // //write the block sum 277 | // if(threadIdx.x == 0) 278 | // { 279 | // if(!blockIdx.x) 280 | // in_q_sz_d = s_mem[tile_sz-1+padding]; 281 | // 282 | // s_mem[tile_sz-1+padding]= 0; 283 | // } 284 | // __syncthreads(); 285 | // 286 | // //down sweep 287 | // for(index_t j=1; j < tile_sz; j <<=1) 288 | // { 289 | // offset >>= 1; 290 | // if(threadIdx.x < j) 291 | // { 292 | // index_t ai = lane*offset + offset - 1; 293 | // index_t bi = ai + offset; 294 | // ai += CONFLICT_FREE_OFFSET(ai); 295 | // bi += CONFLICT_FREE_OFFSET(bi); 296 | // index_t t = s_mem[ai]; 297 | // s_mem[ai] = s_mem[bi]; 298 | // s_mem[bi] += t; 299 | // } 300 | // __syncthreads(); 301 | // } 302 | // __syncthreads(); 303 | // 304 | // const index_t P_DATA = gridDim.x*(blockDim.x<<1); 305 | // tid <<= 1; 306 | // index_t blk_idx = blockIdx.x; 307 | // 308 | // index_t grd_idx_orig= 0; 309 | // index_t grd_idx = grd_idx_orig; 310 | // //should add the offset but we eliminate 311 | // //since CONFLICT_FREE_OFFSET(0) = 0; 312 | // 313 | // while (tid 338 | //__global__ void __post_scan( 339 | // data_t *scan_out_d, 340 | // data_t *blk_sum, 341 | // index_t num_dat, 342 | // index_t num_blk, 343 | // const index_t THD_NUM 344 | // ) 345 | //{ 346 | // extern __shared__ data_t s_mem[]; 347 | // 348 | // const data_t tile_sz = THD_NUM<<1; 349 | // const index_t lane = threadIdx.x<<1; 350 | // index_t tid = threadIdx.x+blockIdx.x*blockDim.x; 351 | // index_t offset = 1; 352 | // const index_t padding = CONFLICT_FREE_OFFSET(tile_sz - 1); 353 | // 354 | // const index_t off_a = CONFLICT_FREE_OFFSET(lane); 355 | // const index_t off_b = CONFLICT_FREE_OFFSET(lane+1); 356 | // ///////////////////////////////////////////////////////// 357 | // //GRID SCAN 358 | // ///////////////////////////////////////////////////////// 359 | // if(lane < num_blk) 360 | // { 361 | // s_mem[lane+off_a]=blk_sum[lane]; 362 | // }else{ 363 | // s_mem[lane+off_a]=0; 364 | // } 365 | // 366 | // if(lane+1 < num_blk) 367 | // { 368 | // s_mem[lane+1+off_b]=blk_sum[lane+1]; 369 | // }else{ 370 | // s_mem[lane+1+off_b]=0; 371 | // } 372 | // __syncthreads(); 373 | // 374 | // //up sweep 375 | // for(index_t j = THD_NUM;j > 0;j>>=1) 376 | // { 377 | // if(threadIdx.x < j) 378 | // { 379 | // index_t ai = offset*lane +offset - 1; 380 | // index_t bi = ai + offset; 381 | // 382 | // ai += CONFLICT_FREE_OFFSET(ai); 383 | // bi += CONFLICT_FREE_OFFSET(bi); 384 | // s_mem[bi] += s_mem[ai]; 385 | // } 386 | // offset <<=1; 387 | // __syncthreads(); 388 | // } 389 | // __syncthreads(); 390 | // 391 | // //write the block sum 392 | // if(!threadIdx.x) 393 | // { 394 | // if(!blockIdx.x) 395 | // in_q_sz_d = s_mem[tile_sz-1+padding]; 396 | // 397 | // s_mem[tile_sz+padding-1] = 0; 398 | // } 399 | // __syncthreads(); 400 | // 401 | // //down sweep 402 | // for(index_t j=1; j < tile_sz; j <<=1) 403 | // { 404 | // offset >>= 1; 405 | // if(threadIdx.x < j) 406 | // { 407 | // index_t ai = lane*offset + offset - 1; 408 | // index_t bi = ai + offset; 409 | // ai += CONFLICT_FREE_OFFSET(ai); 410 | // bi += CONFLICT_FREE_OFFSET(bi); 411 | // index_t t = s_mem[ai]; 412 | // s_mem[ai] = s_mem[bi]; 413 | // s_mem[bi] += t; 414 | // } 415 | // __syncthreads(); 416 | // } 417 | // __syncthreads(); 418 | // 419 | // tid <<= 1; 420 | // index_t blk_idx_orig= blockIdx.x; 421 | // index_t blk_idx = blk_idx_orig + 422 | // CONFLICT_FREE_OFFSET(blk_idx_orig); 423 | // const index_t P_DATA= blockDim.x*(gridDim.x<<1); 424 | // 425 | // while (tid 456 | __global__ void __insp_pre_scan( 457 | data_t *scan_in_d, 458 | data_t *scan_out_d, 459 | data_t *blk_sum, 460 | index_t num_dat, 461 | const index_t THD_NUM 462 | ) 463 | { 464 | const data_t tile_sz = THD_NUM<<1; 465 | const index_t lane = threadIdx.x<<1; 466 | index_t tid = threadIdx.x+blockIdx.x*blockDim.x; 467 | index_t offset = 1; 468 | index_t tid_strip = tid<<1; 469 | const index_t padding = CONFLICT_FREE_OFFSET(tile_sz - 1 ); 470 | 471 | //conflict free 472 | const index_t off_a = CONFLICT_FREE_OFFSET(lane); 473 | const index_t off_b = CONFLICT_FREE_OFFSET(lane+1); 474 | const index_t GRNTY = blockDim.x*gridDim.x; 475 | 476 | 477 | //prefetching danger 478 | extern __shared__ data_t s_mem[]; 479 | 480 | 481 | while(tid_strip < num_dat) 482 | { 483 | s_mem[lane+off_a] = scan_in_d[tid_strip]; 484 | s_mem[lane + 1 + off_b] = scan_in_d[tid_strip + 1]; 485 | __syncthreads(); 486 | 487 | //up sweep 488 | for(index_t j = THD_NUM;j > 0;j>>=1) 489 | { 490 | if(threadIdx.x < j) 491 | { 492 | index_t ai = offset*lane +offset - 1; 493 | index_t bi = ai + offset; 494 | ai += CONFLICT_FREE_OFFSET(ai); 495 | bi += CONFLICT_FREE_OFFSET(bi); 496 | s_mem[bi] += s_mem[ai]; 497 | } 498 | offset <<=1; 499 | __syncthreads(); 500 | } 501 | __syncthreads(); 502 | 503 | //write the block sum 504 | if(threadIdx.x == 0) 505 | { 506 | blk_sum[tid/THD_NUM] = 507 | s_mem[tile_sz -1 + padding]; 508 | s_mem[tile_sz-1 + padding] = 0; 509 | } 510 | __syncthreads(); 511 | 512 | //down sweep 513 | for(index_t j=1; j < tile_sz; j <<=1) 514 | { 515 | offset >>= 1; 516 | if(threadIdx.x < j) 517 | { 518 | index_t ai = lane*offset + offset - 1; 519 | index_t bi = ai + offset; 520 | ai += CONFLICT_FREE_OFFSET(ai); 521 | bi += CONFLICT_FREE_OFFSET(bi); 522 | index_t t = s_mem[ai]; 523 | s_mem[ai] = s_mem[bi]; 524 | s_mem[bi] += t; 525 | } 526 | __syncthreads(); 527 | } 528 | __syncthreads(); 529 | scan_out_d[tid_strip] = s_mem[lane + off_a]; 530 | scan_out_d[tid_strip+1] = s_mem[lane + 1 + off_b]; 531 | 532 | tid += GRNTY; 533 | tid_strip = tid<<1; 534 | } 535 | } 536 | 537 | //////////////////////////////////////////////////////// 538 | //post_scan for inspection 539 | //////////////////////////////////////////////////////// 540 | template 541 | __global__ void __insp_post_scan( 542 | index_t *ex_q_sz_d, 543 | data_t *scan_out_d, 544 | data_t *blk_sum, 545 | index_t num_dat, 546 | index_t num_blk, 547 | const index_t THD_NUM 548 | ) 549 | { 550 | extern __shared__ data_t s_mem[]; 551 | 552 | const data_t tile_sz = THD_NUM<<1; 553 | const index_t lane = threadIdx.x<<1; 554 | index_t tid = threadIdx.x+blockIdx.x*blockDim.x; 555 | index_t offset = 1; 556 | const index_t padding = CONFLICT_FREE_OFFSET(tile_sz - 1); 557 | const index_t off_a = CONFLICT_FREE_OFFSET(lane); 558 | const index_t off_b = CONFLICT_FREE_OFFSET(lane+1); 559 | ///////////////////////////////////////////////////////// 560 | //GRID SCAN 561 | ///////////////////////////////////////////////////////// 562 | if(lane < num_blk) 563 | { 564 | s_mem[lane+off_a]=blk_sum[lane]; 565 | }else{ 566 | s_mem[lane+off_a]=0; 567 | } 568 | 569 | if(lane+1 < num_blk) 570 | { 571 | s_mem[lane+1+off_b]=blk_sum[lane+1]; 572 | }else{ 573 | s_mem[lane+1+off_b]=0; 574 | } 575 | __syncthreads(); 576 | 577 | //up sweep 578 | for(index_t j = THD_NUM;j > 0;j>>=1) 579 | { 580 | if(threadIdx.x < j) 581 | { 582 | index_t ai = offset*lane +offset - 1; 583 | index_t bi = ai + offset; 584 | 585 | ai += CONFLICT_FREE_OFFSET(ai); 586 | bi += CONFLICT_FREE_OFFSET(bi); 587 | s_mem[bi] += s_mem[ai]; 588 | } 589 | offset <<=1; 590 | __syncthreads(); 591 | } 592 | __syncthreads(); 593 | 594 | //write the block sum 595 | if(!threadIdx.x) 596 | { 597 | 598 | if(!blockIdx.x) 599 | { 600 | ex_q_sz_d[0]=s_mem[tile_sz-1+padding]; 601 | // switch(q_t) 602 | // { 603 | // case SML_Q: 604 | // ex_sml_sz_d = s_mem[tile_sz-1+padding]; 605 | // break; 606 | // case MID_Q: 607 | // ex_mid_sz_d = s_mem[tile_sz-1+padding]; 608 | // break; 609 | // case LRG_Q: 610 | // ex_lrg_sz_d = s_mem[tile_sz-1+padding]; 611 | // break; 612 | // default: 613 | // break; 614 | // } 615 | } 616 | s_mem[tile_sz-1+padding]= 0; 617 | } 618 | __syncthreads(); 619 | 620 | //down sweep 621 | for(index_t j=1; j < tile_sz; j <<=1) 622 | { 623 | offset >>= 1; 624 | if(threadIdx.x < j) 625 | { 626 | index_t ai = lane*offset + offset - 1; 627 | index_t bi = ai + offset; 628 | ai += CONFLICT_FREE_OFFSET(ai); 629 | bi += CONFLICT_FREE_OFFSET(bi); 630 | index_t t = s_mem[ai]; 631 | s_mem[ai] = s_mem[bi]; 632 | s_mem[bi] += t; 633 | } 634 | __syncthreads(); 635 | } 636 | __syncthreads(); 637 | 638 | tid <<= 1; 639 | index_t blk_idx_orig= blockIdx.x; 640 | index_t blk_idx = blk_idx_orig + 641 | CONFLICT_FREE_OFFSET(blk_idx_orig); 642 | const index_t P_DATA= gridDim.x*blockDim.x*2; 643 | 644 | while (tid 658 | //__host__ void lrg_scan( 659 | // data_t *scan_ind_d, 660 | // data_t *adj_card_d, 661 | // //TODO requires scan_in_d to be 662 | // // exact times of 663 | // // THD_NUM*2 664 | // data_t *scan_out_d, 665 | // const index_t BLK_NUM, 666 | // const index_t THD_NUM, 667 | // cudaStream_t &stream 668 | // ) 669 | //{ 670 | // const index_t num_dat = ex_q_sz; 671 | // data_t *blk_sum; 672 | // data_t *grd_sum; 673 | // index_t num_grd; 674 | // 675 | // const size_t sz = sizeof(data_t); 676 | // const index_t padding = 677 | // CONFLICT_FREE_OFFSET((THD_NUM<<1) -1); 678 | // index_t num_blk = num_dat/(THD_NUM<<1); 679 | // if (num_dat % (THD_NUM<<1)) 680 | // num_blk ++; 681 | // 682 | // num_grd = num_blk/(THD_NUM<<1); 683 | // if(num_blk%(THD_NUM<<1)) 684 | // num_grd ++; 685 | // 686 | // cudaMalloc((void **)&blk_sum, 687 | // sizeof(data_t)*num_blk); 688 | // 689 | // cudaMalloc((void **)&grd_sum, 690 | // sizeof(data_t)*num_grd); 691 | //if(num_grd>(THD_NUM<<1)) 692 | // std::cout<<"Out of Range\n"; 693 | // __pre_scan 694 | // <<>> 695 | // ( 696 | // scan_ind_d, 697 | // adj_card_d, 698 | // scan_out_d, 699 | // blk_sum, 700 | // num_dat, 701 | // THD_NUM 702 | // ); 703 | // cudaThreadSynchronize(); 704 | // __spine_scan 705 | // <<>> 706 | // ( 707 | // blk_sum, 708 | // grd_sum, 709 | // num_blk, 710 | // THD_NUM 711 | // ); 712 | // cudaThreadSynchronize(); 713 | // __post_scan 714 | // <<>> 715 | // ( 716 | // scan_out_d, 717 | // blk_sum, 718 | // grd_sum, 719 | // num_dat, 720 | // num_grd, 721 | // THD_NUM 722 | // ); 723 | // cudaThreadSynchronize(); 724 | //} 725 | // 726 | //template 727 | //__host__ void mid_scan( 728 | // data_t *scan_ind_d, 729 | // data_t *adj_card_d, 730 | // data_t *scan_out_d, 731 | // const index_t BLK_NUM, 732 | // const index_t THD_NUM, 733 | // cudaStream_t &stream 734 | // ) 735 | //{ 736 | // const index_t num_dat = ex_q_sz; 737 | // data_t *blk_sum; 738 | // const size_t sz = sizeof(data_t); 739 | // const index_t padding = 740 | // CONFLICT_FREE_OFFSET((THD_NUM<<1) -1); 741 | // index_t num_blk = num_dat/(THD_NUM<<1); 742 | // if(num_blk % (THD_NUM<<1)) 743 | // num_blk ++; 744 | //// std::cout<<"mid problem, num dat: "< 749 | // <<>> 750 | // ( 751 | // scan_ind_d, 752 | // adj_card_d, 753 | // scan_out_d, 754 | // blk_sum, 755 | // num_dat, 756 | // THD_NUM 757 | // ); 758 | // 759 | // cudaThreadSynchronize(); 760 | // __post_scan 761 | // <<>> 762 | // ( 763 | // scan_out_d, 764 | // blk_sum, 765 | // num_dat, 766 | // num_blk, 767 | // THD_NUM 768 | // ); 769 | //} 770 | // 771 | //template 772 | //__global__ void sml_scan( 773 | // data_t *scan_ind_d, 774 | // data_t *adj_card_d, 775 | // data_t *scan_out_d, 776 | // const index_t THD_NUM 777 | // ) 778 | //{ 779 | // 780 | // const index_t num_dat = ex_q_sz_d; 781 | // const data_t tile_sz = THD_NUM<<1; 782 | // const index_t lane = threadIdx.x<<1; 783 | // index_t offset = 1; 784 | // index_t idct_a, idct_b; 785 | // const index_t padding = 786 | // CONFLICT_FREE_OFFSET((THD_NUM<<1)-1); 787 | // 788 | // //conflict free 789 | // const index_t off_a = CONFLICT_FREE_OFFSET(lane); 790 | // const index_t off_b = CONFLICT_FREE_OFFSET(lane+1); 791 | // 792 | // //prefetching danger 793 | // extern __shared__ data_t s_mem[]; 794 | // 795 | // if(lane < num_dat) 796 | // { 797 | // idct_a = scan_ind_d[lane]; 798 | // s_mem[lane+off_a] = adj_card_d[idct_a]; 799 | // }else{ 800 | // s_mem[lane+off_a] = 0; 801 | // } 802 | // 803 | // if((lane + 1) < num_dat) 804 | // { 805 | // idct_b = scan_ind_d[lane + 1]; 806 | // s_mem[lane+1+off_b] = adj_card_d[idct_b]; 807 | // }else{ 808 | // s_mem[lane+1+off_b] = 0; 809 | // } 810 | // __syncthreads(); 811 | // 812 | // //up sweep 813 | // for(index_t j = THD_NUM;j > 0;j>>=1) 814 | // { 815 | // if(threadIdx.x < j) 816 | // { 817 | // index_t ai = offset*lane +offset - 1; 818 | // index_t bi = ai + offset; 819 | // ai += CONFLICT_FREE_OFFSET(ai); 820 | // bi += CONFLICT_FREE_OFFSET(bi); 821 | // s_mem[bi] += s_mem[ai]; 822 | // } 823 | // offset <<=1; 824 | // __syncthreads(); 825 | // } 826 | // __syncthreads(); 827 | // 828 | // if(!threadIdx.x) 829 | // { 830 | // in_q_sz_d = s_mem[(THD_NUM<<1)+ padding -1]; 831 | // s_mem[(THD_NUM<<1) + padding -1] = 0; 832 | // } 833 | // __syncthreads(); 834 | // 835 | // //down sweep 836 | // for(index_t j=1; j < tile_sz; j <<=1) 837 | // { 838 | // offset >>= 1; 839 | // if(threadIdx.x < j) 840 | // { 841 | // index_t ai = lane*offset + offset - 1; 842 | // index_t bi = ai + offset; 843 | // ai += CONFLICT_FREE_OFFSET(ai); 844 | // bi += CONFLICT_FREE_OFFSET(bi); 845 | // index_t t = s_mem[ai]; 846 | // s_mem[ai] = s_mem[bi]; 847 | // s_mem[bi] += t; 848 | // } 849 | // __syncthreads(); 850 | // } 851 | // __syncthreads(); 852 | // 853 | // if(lane < num_dat) 854 | // scan_out_d[lane] = s_mem[lane + off_a]; 855 | // 856 | // if((lane+1) < num_dat) 857 | // scan_out_d[lane +1] = s_mem[lane + 1 + off_b]; 858 | //} 859 | 860 | //----------------------------------------- 861 | //For inspection, 862 | //exact threads number of data to scan 863 | //--------------------------------------- 864 | template 865 | __host__ void insp_scan( 866 | data_t *scan_in_d, 867 | //TODO requires scan_in_d to be 868 | // exact times of 869 | // THD_NUM*2 870 | data_t *scan_out_d, 871 | const index_t num_dat, 872 | const index_t BLK_NUM, 873 | const index_t THD_NUM, 874 | index_t *ex_q_sz_d, 875 | cudaStream_t &stream 876 | ) 877 | { 878 | data_t *blk_sum; 879 | const size_t sz = sizeof(data_t); 880 | const index_t num_blk=THD_NUM<<1; 881 | const index_t padding=CONFLICT_FREE_OFFSET((THD_NUM<<1)-1); 882 | cudaMalloc((void **)&blk_sum,sz*num_blk); 883 | 884 | __insp_pre_scan 885 | <<>> 886 | ( 887 | scan_in_d, 888 | scan_out_d, 889 | blk_sum, 890 | num_dat, 891 | THD_NUM 892 | ); 893 | cudaThreadSynchronize(); 894 | __insp_post_scan 895 | <<>> 896 | ( 897 | ex_q_sz_d, 898 | scan_out_d, 899 | blk_sum, 900 | num_dat, 901 | num_blk, 902 | THD_NUM 903 | ); 904 | } 905 | -------------------------------------------------------------------------------- /traversal.cu: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 The George Washington University 3 | * Written by Hang Liu 4 | * Directed by Prof. Howie Huang 5 | * 6 | * https://www.seas.gwu.edu/~howie/ 7 | * Contact: iheartgraph@gmail.com 8 | * 9 | * 10 | * Please cite the following paper: 11 | * 12 | * Hang Liu, H. Howie Huang and Yang Hu. 2016. iBFS: Concurrent Breadth-First Search on GPUs. Proceedings of the 2016 International Conference on Management of Data. ACM. 13 | * 14 | * This file is part of iBFS. 15 | * 16 | * iBFS is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * iBFS is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with iBFS. If not, see . 28 | */ 29 | 30 | #include "gpu_ibfs.cuh" 31 | 32 | void gpu_ibfs:: 33 | debugger(index_t grp_beg) 34 | { 35 | comp_t *last = new comp_t[g->vert_count*joint_count]; 36 | comp_t *curr = new comp_t[g->vert_count*joint_count]; 37 | index_t *front_count=new index_t[concurr_count]; 38 | 39 | H_ERR(cudaMemcpy(last, depth_comp_last, 40 | sizeof(comp_t)*g->vert_count*joint_count, cudaMemcpyDeviceToHost)); 41 | H_ERR(cudaMemcpy(curr, depth_comp_curr, 42 | sizeof(comp_t)*g->vert_count*joint_count, cudaMemcpyDeviceToHost)); 43 | 44 | //ASSUMING one var can hold all bits 45 | for(index_t i=0;ivert_count;++i) 49 | { 50 | if(last[i]!=curr[i]) 51 | { 52 | comp_t curr_var=curr[i]; 53 | comp_t last_var=last[i]; 54 | for(index_t j=0;jsrc_list[i+grp_beg]); 66 | FILE *file=fopen(filename, "a"); 67 | fprintf(file, "%d\n",front_count[i]); 68 | fclose(file); 69 | } 70 | 71 | delete[] front_count; 72 | delete[] last; 73 | delete[] curr; 74 | } 75 | 76 | 77 | //traversal 78 | void gpu_ibfs:: 79 | traversal(index_t grp_beg){ 80 | cudaSetDevice(0); 81 | ex_sml_sz[0] = 0; 82 | ex_mid_sz[0] = 0; 83 | ex_lrg_sz[0] = concurr_count; 84 | depth_t level=0; 85 | 86 | init_bfs(grp_beg); 87 | cudaDeviceSynchronize(); 88 | 89 | #ifdef ENABLE_MONITORING 90 | std::cout<<"Vert-ranger: " 91 | <src_list[grp_beg]<<"~" 92 | <src_list[grp_beg+concurr_count-1]<<"\n"; 93 | double tm_insp; 94 | double tm_expd; 95 | double tm_expand = 0.0; 96 | double tm_inspect = 0.0; 97 | debugger(grp_beg); 98 | #endif 99 | 100 | is_done[0]=false; 101 | for(level=1;;level++){ 102 | if(is_done[0])break; 103 | 104 | //---------------------- 105 | //Expand ex_qs and mark frontier in depth_d 106 | //------------------------------------------------ 107 | #ifdef ENABLE_MONITORING 108 | tm_expd=wtime(); 109 | #endif 110 | expander(level); 111 | cudaDeviceSynchronize(); 112 | 113 | #ifdef ENABLE_MONITORING 114 | tm_expd=wtime()-tm_expd; 115 | debugger(grp_beg); 116 | tm_insp=wtime(); 117 | #endif 118 | //----------------------- 119 | //Generate ex_qs from depth_d 120 | //--------------------------------- 121 | inspector(level); 122 | cudaDeviceSynchronize(); 123 | #ifdef ENABLE_MONITORING 124 | tm_insp=wtime()-tm_insp; 125 | tm_expand += tm_expd; 126 | tm_inspect += tm_insp; 127 | std::cout<<"@level-"<<(int)level<<"-insp-expd: " 128 | <. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #define INFTY int(1<<30) 43 | using namespace std; 44 | 45 | typedef long int vertex_t; 46 | typedef long int index_t; 47 | 48 | inline off_t fsize(const char *filename) { 49 | struct stat st; 50 | if (stat(filename, &st) == 0) 51 | return st.st_size; 52 | return -1; 53 | } 54 | 55 | 56 | int main(int argc, char** argv){ 57 | int fd,i; 58 | char* ss_head; 59 | char* ss; 60 | 61 | std::cout<<"Input: ./exe tuple_file(text) " 62 | <<"reverse_the_edge(1 reverse, 0 not reverse) lines_to_skip\n"; 63 | if(argc<4){printf("Wrong input\n");exit(-1);} 64 | 65 | size_t file_size = fsize(argv[1]); 66 | int is_reverse=(atol(argv[2])==1); 67 | long skip_head=atol(argv[3]); 68 | 69 | 70 | fd=open(argv[1],O_CREAT|O_RDWR,00666 ); 71 | if(fd == -1) 72 | { 73 | printf("%s open error\n", argv[1]); 74 | perror("open"); 75 | exit(-1); 76 | } 77 | 78 | ss_head = (char*)mmap(NULL,file_size,PROT_READ|PROT_WRITE,MAP_PRIVATE,fd,0); 79 | assert(ss_head != MAP_FAILED); 80 | size_t head_offset=0; 81 | int skip_count = 0; 82 | while(true) 83 | { 84 | if(skip_count == skip_head) break; 85 | if(head_offset == file_size && 86 | skip_count < skip_head) 87 | { 88 | std::cout<<"Eorr: skip more lines than the file has\n\n\n"; 89 | exit(-1); 90 | } 91 | 92 | head_offset++; 93 | if(ss_head[head_offset]=='\n') 94 | { 95 | head_offset++; 96 | skip_count++; 97 | if(skip_count == skip_head) break; 98 | } 99 | } 100 | 101 | ss = &ss_head[head_offset]; 102 | file_size -= head_offset; 103 | 104 | size_t curr=0; 105 | size_t next=0; 106 | 107 | //step 1. vert_count,edge_count, 108 | size_t edge_count=0; 109 | size_t vert_count; 110 | vertex_t v_max = 0; 111 | vertex_t v_min = INFTY;//as infinity 112 | vertex_t a; 113 | while(nexta){ 120 | v_min = a; 121 | } 122 | 123 | while((ss[next]!=' ')&&(ss[next]!='\n')&&(ss[next]!='\t')){ 124 | next++; 125 | } 126 | while((ss[next]==' ')||(ss[next]=='\n')||(ss[next]=='\t')){ 127 | next++; 128 | } 129 | curr = next; 130 | 131 | //one vertex is counted once 132 | edge_count++; 133 | } 134 | 135 | const index_t line_count=edge_count>>1; 136 | if(!is_reverse) edge_count >>=1; 137 | 138 | vert_count = v_max - v_min + 1; 139 | assert(v_min0){ 283 | cout<. 28 | */ 29 | 30 | #ifndef __UTIL_H__ 31 | #define __UTIL_H__ 32 | #include 33 | #include 34 | #include 35 | 36 | inline off_t fsize(const char *filename) { 37 | struct stat st; 38 | if (stat(filename, &st) == 0) 39 | return st.st_size; 40 | return -1; 41 | } 42 | 43 | static void HandleError( cudaError_t err, 44 | const char *file, 45 | int line ) { 46 | if (err != cudaSuccess) { 47 | printf( "%s in %s at line %d\n", \ 48 | cudaGetErrorString( err ), 49 | file, line ); 50 | exit( EXIT_FAILURE ); 51 | } 52 | } 53 | #define H_ERR( err ) \ 54 | (HandleError( err, __FILE__, __LINE__ )) 55 | 56 | ////////////////////////////////////////////////// 57 | //SCALE*THDS_NUMS*sizeof(int) should be 58 | //limited by the size of the shared memory 59 | ///////////////////////////////////////////////// 60 | ////////////////////////////////////////////////// 61 | #define THDS_NUM 256 62 | #define BLKS_NUM 256 63 | #define OMP_THDS 24 64 | #define V_NON_INC -1 65 | #define V_INI_HUB -2 66 | 67 | #define VALIDATE_TIMES 1 68 | #define NUM_SRC 128 69 | #define INFTY 255 70 | #define Q_CARD 3 71 | enum ex_q_t 72 | { 73 | SML_Q, 74 | MID_Q, 75 | LRG_Q, 76 | NONE 77 | }; 78 | 79 | //-------------------------- 80 | typedef int index_t; 81 | typedef int vertex_t; 82 | typedef unsigned char depth_t; 83 | typedef uint4 comp_t; 84 | //-------------------------------- 85 | 86 | //operator overloading 87 | inline __host__ __device__ uint4 operator-(uint4 a, uint4 b) 88 | { 89 | return make_uint4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); 90 | } 91 | 92 | inline __host__ __device__ uint4 operator|=(uint4 a, uint4 b) 93 | { 94 | return make_uint4(a.x |= b.x, a.y |= b.y, a.z |= b.z, a.w |= b.w); 95 | } 96 | 97 | inline __host__ __device__ uint4 operator|(uint4 a, uint4 b) 98 | { 99 | return make_uint4(a.x | b.x, a.y | b.y, a.z | b.z, a.w | b.w); 100 | } 101 | 102 | inline __host__ __device__ uint4 operator^(uint4 a, uint4 b) 103 | { 104 | return make_uint4(a.x ^ b.x, a.y ^ b.y, a.z ^ b.z, a.w ^ b.w); 105 | } 106 | 107 | inline __host__ __device__ uint4 operator~(uint4 a) 108 | { 109 | return make_uint4(~a.x, ~a.y, ~a.z, ~a.w); 110 | } 111 | 112 | inline __host__ __device__ uint4 make_uint4(int a) 113 | { 114 | return make_uint4(a, 0, 0, 0); 115 | } 116 | 117 | inline __host__ __device__ uint4 operator<<(uint4 a, int b) 118 | { 119 | if(b<32) a.x=(a.x< 5 | index_t validate( 6 | depth_t *depth_h, 7 | vertex_t *adj_list, 8 | index_t *adj_card, 9 | index_t *beg_pos, 10 | index_t vert_count) 11 | { 12 | 13 | //divide the adjacency vertices of this vertex into two parts 14 | //-parent part: all the vertices connected to the parent part 15 | // should have smaller or equal to base_depth 16 | //-children part: all vertices connected to the children part 17 | // should have larger or equal to base_depth 18 | //depth difference should be no more than 1 19 | depth_t base_depth; 20 | char err_type; 21 | for(int i = 0; i< vert_count; i++){ 22 | base_depth = depth_h[i]; 23 | if(base_depth ==INFTY) continue; 24 | 25 | if(!base_depth){//src vertex 26 | for(int j = beg_pos[i]; j< beg_pos[i]+adj_card[i]; j++) 27 | if((depth_h[adj_list[j]]!= 1) && (adj_list[j]!=i)){ 28 | std::cout<<"Vert: "< 62 | void report( 63 | index_t &agg_tr_edges, 64 | index_t &agg_tr_v, 65 | depth_t *depth_h, 66 | index_t *adj_card, 67 | index_t vert_count) 68 | { 69 | agg_tr_edges = 0; 70 | agg_tr_v = 0; 71 | for(index_t i = 0; i< vert_count; i++) 72 | if(depth_h[i] != INFTY){ 73 | agg_tr_v ++; 74 | agg_tr_edges += adj_card[i]; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /write_result.cuh: -------------------------------------------------------------------------------- 1 | #include "graph.h" 2 | #include 3 | #include 4 | #include 5 | template 6 | int graph:: 7 | write_result() 8 | { 9 | std::stringstream ss; 10 | srand(time(NULL)); 11 | std::ofstream result_file; 12 | std::string file_str="bfs_result."; 13 | ss< 5 | #include 6 | 7 | double wtime() 8 | { 9 | double time[2]; 10 | struct timeval time1; 11 | gettimeofday(&time1, NULL); 12 | 13 | time[0]=time1.tv_sec; 14 | time[1]=time1.tv_usec; 15 | 16 | return time[0] + time[1]*1.0e-6; 17 | } 18 | 19 | 20 | #endif 21 | --------------------------------------------------------------------------------