C :: Accessing Files From Multiple Processors

Apr 9, 2013

I have a big un-editable program, A, which I need to run for like a 1000 different input files. It takes about 15 minutes for each file, so a little parallelisation wouldn't hurt.

I have installed openmpi and it works fine. I have made a small program, B, which selects an input file, moves it to another directory, calls program A with the path to the selected input file and then - when A is done - selects a new input file etc. It should loop until there are no more files in the initial directory.

The problem is this: When I have several processors they might pick the same file and that leads to errors. I have a working program, but it is not pretty.

Code:

#include <stdio.h>
#include <mpi.h>
#include <dirent.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int num_procs, procs_id, i, exit;
struct dirent *ent;

[Code]...

Every time a processor tries to move a file that another processor has just moved, the output shows an error message before looping to the next file and trying again. It works, but it is a bit annoying. So my questions are:

1) Can I switch off the error message somehow?

2) Is there a better way to do this?

View 3 Replies


ADVERTISEMENT

C++ :: Display Last 1000 Lines From Multiple Text Files (log Files)

Jan 16, 2014

I am writing a piece of code that requires me to display the last 1000 lines from a multiple text files (log files). FYI, I am running on Linux and using g++.

I have a log file from which - if it contains more than 1000 lines, I need to display the last 1000 lines. However, the log file could get rotated. So, in case where the current log file contains less than 1000 lines, I have to go to older log file and display the remaining. For e.g., if log got rotated and new log file contains 20 lines, I have to display the 980 lines from old log file + 20 from current log files.

What is the best way to do this? Even an outline algorithm will work.

View 6 Replies View Related

C++ :: Accessing Variables From Other Files

Sep 26, 2014

I don't have in depth code or anything. I tried this but can't seem to wrap my head around it.

Code: //header.h
namespace test {
int arr[5];

[Code] ....

Also tried putting int arr[5] in a Test class within test.h.

I have 2 structs in another file, the main, and want to make an instance of the arr variable, in a separate header, for each.

View 2 Replies View Related

C++ :: Accessing And Working With Vector From Multiple Threads

Oct 20, 2014

I have a vector that I would like to access and work with from multiple threads. I have created an example below to illustrate the functionality that I would like to accomplish.

The goals are to be (1) high speed, (2) thread safe, and (3) *if possible* continue to use vectors as my larger project uses vectors all over the place and as such I would like to maintain that.

However, if I need to switch from vectors to something else then I am open to that as well.

The following example below compiles but crashes rather quickly because it is not thread safe.

How I can fix the example below which I can then apply to my larger project?

#include <string>
#include <vector>
#include <ctime>
#include <thread>
#include <iostream>
#include <random>
#include <atomic>
#include <algorithm>
enum EmployeeType {

[Code] ....

View 1 Replies View Related

C :: Accessing Pointers From Other Source Files

Oct 16, 2013

I've recently been learning GTK (though this question is not specific to GTK), and came across a situation that I was unsure how to best handle. Essentially, I've defined several pointers in one source file, and I want to access those pointers from other source files.

The structure of my GTK programs generally follow this pattern:

- "main.c": Define the main window and run GTK main
- "create_window.c": Create and arrange widget pointers in the main window
- "program_functions.c": All other source code for the project (several source files in reality)

In "create_window.c", I declare and define all my widget pointers (e.g. label). If I need to modify those widgets in "program_functions.c" for any reason (say, to change the value of a label), I need access to the pointers created in "create_window.c".

My first thought was to create a global struct of pointers in "create_window.c", and extern that struct to the other source files that need access to the pointers. The thing I don't like about this approach is spreading globals across my program.

My second idea was to create access functions in "create_window.c" where the necessary pointers are statically stored. The first time I call this function (immediately after creating a widget), a static copy of that pointer is stored in the function. Each time afterwards when I call that function (from other source files), I simply use that static pointer to access the widget of interest.

Example:
Code: void edit_label_1(GtkWidget *label_set, const char *string)
{
static GtkWidget *label = NULL;

[Code].....

Are either one of the approaches considered acceptable by standard practice?

View 2 Replies View Related

C/C++ :: Creating And Accessing Index Files?

Oct 27, 2014

I'm supposed to read in a data file with fixed length records and fields, create a sorted index list in memory, and save that list to a file. Then I'm to write a second program that interactively (via the Linux command line) takes a key and the index file name, opens and loads the index file, searches for the given key using the index table, and opens and returns the correct data record.

The original file consists of a list of records with a key (int), a name (string of 8 characters max), a code (int) and a cost (double).

The RRN (relative record number) begins at 1, with the RRN at 0 representing a dummy record with only the size in the first entry.

Here is the data file I will be using.

8 blank 0 0.0
12345 Item06 45 14.2
12434 Item04 21 17.3
12382 Item09 62 41.37

[Code]....

The "File is Open" part will be replaced once I figure out what do do once the file is open, just used this message to verify that it was opening the file.

View 12 Replies View Related

C++ ::  Multiple Files Causes (Multiple Definition) Error?

Jul 15, 2013

I'm using multiple C++ files in one project for the first time. Both have need to include a protected (#ifndef) header file. However, when I do that, I get a multiple definition error.

From what I found from research, adding the word inline before the function fixes the error. Is this the right way to do this, and why does it work? Should I make a habbit of just declaring any function that might be used in two .cpp files as inline?

View 5 Replies View Related

Visual C++ :: Number Of Hardware Processors (cores)

Apr 24, 2014

Apparently there are various methods (GetSystemInfo() / GetLogicalProcessorInfoEx() etc) which can return the number of available processors. But they usually return the number of logical processors and they're affected by stuff like hyperthreading. So for example, depending on how you get the information, a dual-core CPU can either return 1, 2 or 4 processors.

I've been asked if there's any simple way to retrieve the actual number of physical processor cores - i.e. such that a dual core CPU will always get returned as '2'. An 8-core CPU would return '8' etc.

View 9 Replies View Related

C++ ::  Headers With Multiple CPP Files

Mar 22, 2013

So I have a rather large (for me) project, requiring me to have two .cpp files and a header. Anyway, both of the .cpp files #include the header file, but I recieve linker errors because the variables and functions in the header are declared and defined twice (once in each .cpp file). How am I supposed to do this?

View 8 Replies View Related

C# :: Classes Across Multiple Files?

Sep 24, 2014

We typically don't bother with massive, monolithic code files that get processed from top to bottom. In the Object Oriented world, code files don't mean much. In fact, in C#, I could have multiple classes defined in one file, or have one class split across several files.

View 7 Replies View Related

C/C++ :: Using Multiple Files And Includes

Mar 23, 2014

I am struggling with the concept of having different ccp's and header files. I made a really bad example project for representation, but basically my question is are any of the #includes unnecessary that I have? Technically it functions, but if I am doing it wrong I want to prevent myself from starting bad habits in the future. My code just basically uses strings and sets a name and prints it. My code is really bad, but I wanted to just use includes in such a way for a quick example.

//MAIN.CCP
#include "functions.h"
using namespace std;
int main()

[Code]......

View 1 Replies View Related

C/C++ :: How To Get Multiple Source Files To Run One After The Other

May 16, 2012

I am trying to run multiple source files but right after the first one finishes running the program closes and doesn't move on ...

View 2 Replies View Related

C :: Compile Multiple Source Files

Mar 7, 2013

How I can compile multiple source file in visual studio 2012 ???

View 1 Replies View Related

C :: Variable Access Across Multiple Files

Sep 7, 2013

I was trying out programs based on extern and as i understand, this is useful when accessing variables across multiple files having only one definition. But i tried a simple program as below without "extern" and thing seem to work when i expected it would fail during linking process

Code:
file5.c
1 #include <stdio.h>
2 #include "var.h"
3
4 int main() {
5
6 printf("
File5.c a = %d", a);

[Code] .....

As i have included "var.h" in all header files without extern, "int a" would be included in both the .c file and during linking, compiler should have thrown a warning or error message but it compiles file without any issue. Shouldn't var.h have the following "extern int a"?

View 8 Replies View Related

C++ :: Using A Header File Across Multiple Files?

Aug 2, 2014

So say I create a header file which contains a list of structs, and I want to use these structs through out my source and some of my classes... how would I accomplish this?

When I try to do it via #include, I get re-definition errors, due to the nature of #pragma once. If I switch to #ifndef then I lack defenitions in files other than the source.

Is there a way to define things such as structs across multiple files, which doesn't lead to re-definition errors, and doesn't involve manually re-created all the structs for each file?

View 2 Replies View Related

C++ :: Using Ifstream To Open Multiple Files

Apr 28, 2014

I am currently working on a C++ program for school. I am actually not finding too much difficulty in constructing the functions, enum-types, arrays and structs, however, I am finding great difficulty in using on ifstream variable to open multiple files.

I have posted the entire code that I have so far (even though I have pinpointed the issue to not properly opening the second file in ifstream).

I spent a couple of hours getting rid of certain functions/procedures, loops and variables and I get the same output (if what I removed doesnt crash it). I also get the same output whether I "open" the second file or not (meaning I removed all of the code for it and got the same output).

Here is the code (it's not finished because I am stuck on this file issue). It's a bit messy since I am now in debug mode versus program mode:

View 8 Replies View Related

C++ :: Passing In Multiple Text Files

Oct 6, 2014

I have been working on code for quite some time and am able to successfully read in a text document and take certain words and information that I need. The issue is that I need to read in close to 100 plus documents and was wondering how I could read in the multiple documents. I thought about creating a structure of arrays and have each text document be an element and walk through taking each document but I am not sure how this works.

View 8 Replies View Related

C++ :: Global Variables For Multiple CPP Files

Jan 19, 2014

I am trying to get variables that are global to multiple files. I have mananged to make constant variables that are global but maybe not in the best way. In the header i have the constant variables being defined:

const int variable_Name = 5;

And the cpp file:

#include <iostream>
using namespace std;
#include "vars.h"
int main ( ) {
cout << variable_Name<< endl;
system ("pause");
return 0;
}

Is there a better way to do this and to make the variables able to be changed within the cpp files.

View 7 Replies View Related

C++ :: Creating Multiple Files Using Array?

May 29, 2014

I am trying to create n number of files (n being an integer), by passing the name through a character array (and obviously changing its value at each iteration). But the problem is that the program compiles and executes but not a single file is created.

Here is my code snippet.

void file_phipsi(int m)
{
int a=0,n=0;
char *str1;

[Code].....

View 4 Replies View Related

C++ :: How To Write Data Into Multiple / Different Files

May 7, 2013

I am new to c++ programming i just want to know how to write the data into different files.Suppose my input files has 1-8 ids so each id data must be stored into each different file. And below is my code.

#include<fstream>
#include<iostream>
#include <cstdlib>
#include <algorithm>
#include<list>
#include <math.h>
#include<conio.h>
#include<string>
#define PI 3.14159265
using namespace std;
double angle;
ifstream indata;
ofstream outfile;

[Code] .....

View 1 Replies View Related

C++ ::  Split A Namespace In Multiple Files?

Jan 11, 2013

I want to create a namespace named MyNS.

Can I define it in multiple files?

I mean:

file1.h
namespace MyNS {
const int File1 = 0;
} file2.h
namespace MyNS {
const int File2 = 1;

[Code] .....

View 6 Replies View Related

C/C++ :: Multiple Class Implementation Files?

Apr 14, 2014

I have attached my code below and I am stuck in what to do next to make an instance of the dateCls so I can use the instance to assign the open date. By instance I mean like create an instance of the class, like this: dateCls myFirstInstance; And everything in the dateCls I can access through the . operator. So far my code looks like this..what I should do? Lastly, I am using derived data from I think the bankAccountCls.

I need the main program to output this data:

dateCls openDate(01, 03, 2012, "open date");
saveAccountCls s1("1001", 300.50, 0.12);
s1.setDate(openDate);
s1.print();
s1.deposit(100, 01, 05, 2012);
s1.print();
s1.withdraw(50, 01, 10, 2012);

[code]....

View 8 Replies View Related

C++ :: Where To Put The Include Directive And Using Namespace Std With Multiple Files

Aug 23, 2014

I have two files that I want to compile:

main.cpp
Code:
#include <iostream>
using namespace std;
int ReadNumber();
void WriteAnswer();

[Code] .....

The compiler complains:
io.cpp||In function 'int ReadNumber()':|
io.cpp|3|error: 'cin' was not declared in this scope|
io.cpp||In function 'void WriteAnswer()':|
io.cpp|7|error: 'cout' was not declared in this scope|
io.cpp|7|error: 'endl' was not declared in this scope|

In io.cpp file, should I put the two statements ("include <iostream>" and "using namespace std") at the top, outside of the functions?

Or should I put the two statements inside each of the functions?

View 4 Replies View Related

C++ :: Logging In Multiple Files - Compilation Errors

Sep 25, 2014

I am working on one application that requires extensive logging so I want to create a log file of each day during execution.

I tried easylogging++ but i am unable to use into multiple files. If i try to use in other file. I get compilation errors of using same functions or methods already defined.

How can i use macro to hide the implementation of logging in one class to other ??

View 1 Replies View Related

C++ :: Printing To Multiple Files Because Output Is Too Large?

Apr 18, 2013

I have managed to make a program that permutates a string with repetition.

I ran it to permutate "abcdefghijklmnopqrstuvwxyz1234567890" with a limit of 5 characters.

This took a little over 5 hours for my pc to process this and I ended up with a .txt 403MB in size. Needless to say I am unable to open this .txt in notepad without Notepad.exe not responding and me having to end the process.

So what I want to do is modify my code to break up the output in to several files rather than one. Possibly all permutations starting with a in one file, b in another, etc.

Here is my current code:
#include <iostream>
#include <string>
#include <sstream>

[Code]....

As you can see it currently appends permutation.txt with all output. I would like it to make files like this permut_5char_a.txt, permut_5char_b.txt, etc.

View 12 Replies View Related

C++ :: Reading Multiple Text Files In Program

May 31, 2013

I want to know how to read multiple text files in this program... I have 5 text files(order1,order2,...order5).

#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<windows.h>
using namespace std;
class{

[Code] ....

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved