/* MPI Triad Census by Kris Schnee First attempt at a program that performs a basic type of triad census. Meant for Steam user data, involving undirected graphs of low degree. Strategy: -Load the "egonet" data into structs that each list a certain node and its neighbors. -Divide up the egonet data and assign to some processes. -Each process P gets put in charge of some set of nodes "this_process_nodes". -For each process P: -For each node this_node in this_process_nodes: -Let "groups_to_examine" := [] -For each neighbor in this_node's neighbors: -Let A = this_node -Let B = neighbor -For every other node C in the range (0,highest_node): groups_to_examine += (A,B,C) [(0,3,4),(0,3,5),(0,3,6)...(0,7,1),(0,7,2)...] For each group in groups_to_examine: links = 1 ## We know AB exists. Examine AC, then BC. THEIR VERSION For A in list of nodes w/neighbors: For B in neighbors of A with < number: Find # of single-edge triads AB is involved in, which is (N- (union of neighbors of A&B) ) For A in entire list of nodes in the graph, that DO have neighbors listed: For B in "neighbors of A that have a smaller # than A": For C in "the union of all neighbors of A and of B": (13,0,5) */ #include #include "mpi.h" int main(int n_args, char** args) { // Invoke MPI for the hell of it. Not really using it yet. MPI_Init(&n_args, &args); printf("\n\n*** Demo of file I/O ***\n\n"); // Open a file for reading text. FILE* input_file = fopen("input.txt","rt"); if(input_file == NULL) { printf("Error: Couldn't find/open input file \"input.txt\". Create one, if not!\n"); return(1); } printf("Got the file open successfully. Now trying to read and display it line by line.\n"); char line[80]; // Stores up to 80 characters of text from one line of the file. Should be safe from buffer overflow hacks due to the way it's being used. while(fgets(line, 80, input_file) != NULL ) // Try to read a line, ending on a failure. { printf(line); // Since lines end with \n characters, a newline gets printed automatically. } // Note: To convert a string to an int: // int x; // sscanf(input_string,"%d",&x); fclose(input_file); printf("Now trying to write an output file.\n"); // Open an output file for writing. FILE* output_file = fopen("output.txt","w"); // Note: overwrites old content, which is what we want. if(output_file == NULL) { printf("Error: Couldn't open output file.\n"); return(1); } // Write some junk. int i; for(i=0;i<10;i++) { fputs("Some text\n",output_file); } fclose(output_file); printf("Success."); return 0; }