473,383 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

fseek-fread error

Hi;

I have a c program that uses mpi library to run on parallel arhitecture. First i coded serial program and it worked perfectly. But the parallel one did not run. I found the error but could not solve it.

The error is: the "fseek" and "fread" functions does not return the correct values.
Expand|Select|Wrap|Line Numbers
  1. fseek(wav_fp,40L,SEEK_SET);fread(&str,4,1,wav_fp);
this code must return "str" = "81913" but i get "-442495"

Thanks.
Jan 6 '08 #1
7 5898
weaknessforcats
9,208 Expert Mod 8TB
Are you reading as text or as binary??
Jan 7 '08 #2
Are you reading as text or as binary??
As binary..

In serial version of this code runs true as parallel program with mpi library can not get the right result.
Jan 8 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
Then you have a multithreading race operating.

If this file is a shared resource, you may have to access it within a critical section.
Jan 8 '08 #4
no, it is not multithreading program, it is a parallel program, the fseek's offset value is long type and this is causing segmentation fault problem.
Jan 9 '08 #5
weaknessforcats
9,208 Expert Mod 8TB
I'm sorry but what is the difference between a parallel program and a multi-threaded one??
Jan 9 '08 #6
in parallel programing a processor executes a part of the job, but in multi-thread programming whole job is done by one processor.
Jan 10 '08 #7
weaknessforcats
9,208 Expert Mod 8TB
in parallel programing a processor executes a part of the job, but in multi-thread programming whole job is done by one processor.
This statement is absolutely false.

A parallel program is a program where sections are run in parallel in real time. This requires multiple processors. Each processor runs a section. Each section is called a thread.

A multi-threaded program is a program that can be run as a parallel program. It can also be run using one processsor but only one thread executes at a time. The operating system will multi-task to make it appear that there is more than one processor giving the illusion that the threads are running in parallel.

You have to be certain that any data shared between threads is protected by a critical section, mutex, sempaphore, spin-lock or something that prevents two threads from writing simultaneously to the same resource.
Jan 10 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Leslaw Bieniasz | last post by:
Hello, I am trying to fastly read large binary files (order of 100-200 MB) using ftell() and fseek(). My class gets a pointer to the data stored in the file, and then uses fseek() to access and...
62
by: Christopher Benson-Manica | last post by:
On thinking about the "replace a word in a file" thread, I wondered how easy it would be to accomplish the same thing with only one file pointer. This led me to some questions... "For a text...
15
by: TJ Walls | last post by:
Hello All, I am baffled ... I am trying to improve the speed of a program that I have written that performs random access within a file. It relies heavily on fseek and is very slow. To test, I...
20
by: Xenos | last post by:
Can anyone tell me what the standard says about using fseek (on a binary file) to seek past the end-of-file? I can't find anything in my (draft) copy of the standard, nor in the FAQ. Thanks
2
by: cedarson | last post by:
I am writing a program and have been instructeed to use the 'fseek', 'ftell', and 'stat' functions, however, after looking in the online manual for each of these, I am still unsure on how to use...
10
by: Kenneth Brody | last post by:
I recently ran into an "issue" related to text files and ftell/fseek, and I'd like to know if it's a bug, or simply an annoying, but still conforming, implementation. The platform is Windows,...
3
by: Chen ShuSheng | last post by:
HI, I am now study a segment of codes: ------------------------ printf("%p\t",fp); /*add by me*/ fseek(fp, 0L, SEEK_END); /* go to end of file */ printf("%p\t",fp); ...
23
by: Dmitry Belous | last post by:
Why when I uncomment fseek line buf become empty? #define _GNU_SOURCE #include <stdio.h> int main() { char *buf = 0; int size = 0; FILE* f = open_memstream(&buf, &size); fwrite("test", 1, 4,...
6
by: ericunfuk | last post by:
A basic question: When the documentation says "fseek() clears EOF indecator, does it mean when you seek over EOF, EOF is no longer at the original position and hence removed?Say, after I seek...
13
by: thomas.mertes | last post by:
Hello Recently I discovered some problem. I have some C code which determines how many bytes are available in a file. Later I use this information to malloc a buffer of the correct size before...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.