Software Archive
Read-only legacy content
17061 Discussions

Problem of fault segmentation

amina-jarraya
Beginner
451 Views
Hello,

I meet the problem of fault segmentation when executing the following program (privrate.cpp) with Cilk plus :

#include
#include
#include

class storage
{
public:

storage() {};

//***** ary

void set_ary (int *ary) {
ary_ = ary;
}

void set_ary (int i, int val) {

ary_ = val;
}

int * ary() { return ary_; }


private:
int *ary_;

};


class storage_holder
{
struct Monoid: cilk::monoid_base
{
static void reduce (storage *left, storage *right) {}
};
private:
cilk::reducer imp_;
public:

storage_holder() : imp_() {}

//***** ary

void set_ary(int *ary) {
storage &v = imp_.view();
v.set_ary(ary);
}

void set_ary (int i, int val) {
storage &v = imp_.view();
v.set_ary(i, val);
}

int * ary() { return imp_.view().ary(); }

}; // class storage_holder


int main(int argc, char* argv[])
{

storage_holder vars;

vars.set_ary (new int[10000]);

cilk_for (int i = 0; i < 10000; i++) {
printf ("thread %d \\n", i);
vars.set_ary(i, i);
}

printf("End \\n");

return 0;
}


The result of execution is :

*compilation :

amina@amina-laptop:~/projet/cilkplus-install/examples/test$ icpc -pthread -o private private.cpp -lcilkrts

* execution :

amina@amina-laptop:~/projet/cilkplus-install/examples/test$ ./private
thread 0
thread 1
thread 2
thread 3
....
thread 176
thread 5000
thread 177
thread 178
thread 179
thread 180
thread 181
thread 182
Erreur de segmentation

* execution with cilkscreen :

amina@amina-laptop:~/projet/cilkplus-install/examples/test$ cilkscreen ./private
Cilkscreen Race Detector V2.0.0, Build 1113
thread 0
thread 5000
thread 1

Warning: Instrumentation never enabled - no Cilk Plus code found
1 error found by Cilkscreen
process killed by signal -10


Have you an idea for this problem ? the program code is it correct ?

When i change the number of iteration to 1000, it works fine. but i have to use 10000 iterations.

For your information, i have to declare the ary variable as private to each thread.

Best regards,
0 Kudos
1 Solution
Georg_Z_Intel
Employee
451 Views
Hello,

the problem here is that for a new strand the member ary_ of class strorage is not initialized. A solution for your example would be the following:
[cpp]...

class storage
{
    public:

        storage() {}

        //***** ary

        void set_ary (int *ary) {
            ary_ = ary; // Initialize once for all strands
        }

        void set_ary (int i, int val) {

            ary_ = val;
        }

        int * ary() { return ary_; }


    private:
        static int *ary_;

};

int *storage::ary_ = 0;

...[/cpp]

Since an object of class storage has only a few bytes it's not related to limited memory.

If you used CILK_NWORKERS=1 (only one strand) there's no problem with your original version because only one object of type storage exists which is already initialized correctly. However, more strands (>= 2) require a local copy of storage object, each, (hyper-object) and hence the pointer ary_ is not initialized for strands other than the original one.

Best regards,

Georg Zitzlsberger

View solution in original post

0 Kudos
6 Replies
SergeyKostrov
Valued Contributor II
451 Views
...
Have you an idea for this problem ? The program code is it correct ?

[SergeyK] I didn't have a chance to execute it.

When i change the number of iteration to 1000, it works fine. but i have to use 10000 iterations.
...


I could only assume that you don't have enough memory for the Test-Case with 10,000 iterations.

My estimations,in case of a 32-bit Windows platform without AWE(2GB memory limit for an application), are as follows:

( 2^31/ 4 ( sizeof(int) ) / 10,000 ( number of iterations ) )~= 53,687

and this is amaximum size of an array that could be theoretically allocated.

Your Test-Case fails when~380MB is allocated. Could you verify it with a Task Manager? I would also
verify a size of aVirtual Memory file.

Best regards,
Sergey

0 Kudos
amina-jarraya
Beginner
451 Views
Thank you for your reply.
I share your opinion that it's a problem of insuffisance of memory. but sometimes it work's fine and sometimes fails with fault segmentation.
You find on the attached file a printscreen "Capture-3.png" that shows the task manager when success execution with 10000 iterations.

Now, i have two others of the problem "fault segmentation" : i work with 38 iterations and i added an index for my table ary which is a private variable for each thread. the following code modified :

#include
#include
#include
#include

class storage
{
public:

storage() : indice_(0) {};

//***** ary

void set_ary (int *ary) {
ary_ = ary;
}

void set_ary (int i, int val) {

ary_ = val;
}

int * ary() { return ary_; }

//****** indice

void set_indice (int indice) {
indice_ = indice;
}

int indice() { return indice_; }


private:
int *ary_;
int indice_;

};


class storage_holder
{
struct Monoid: cilk::monoid_base
{
static void reduce (storage *left, storage *right) {}
};
private:
cilk::reducer imp_;
public:

storage_holder() : imp_() {}


//***** ary

void set_ary(int *ary) {
storage &v = imp_.view();
v.set_ary(ary);
}

void set_ary (int i, int val) {
storage &v = imp_.view();
v.set_ary(i, val);
}

int * ary() { return imp_.view().ary(); }

//***** indice

void set_indice(int indice) {
storage &v = imp_.view();
v.set_indice(indice);
}

int indice() { return imp_.view().indice(); }



}; // class storage_holder


int main(int argc, char* argv[])
{

storage_holder vars;
vars.set_ary (new int[38]);

cilk_for (int i = 0; i < 38; i++) {

cilkscreen::fake_mutex *m = cilkscreen::create_fake_mutex();
m->lock();

printf ("thread %d \n", i);
printf ("--indice %d \n", vars.indice());

m->unlock();
cilkscreen::destroy_fake_mutex(m);

vars.set_ary(vars.indice(), i);
vars.set_indice(vars.indice() + 1 );
}

printf("End \n");

return 0;
}


When running this code, we sometimes see this two problems:

* first problem :

execution with cilk screen :

amina@amina-laptop:~/projet/cilkplus-install/examples/test$ cilkscreen ./private
Cilkscreen Race Detector V2.0.0, Build 1113
thread 0
--indice 0
thread 1
--indice 1
thread 2
--indice 2
thread 3
--indice 3
thread 19
thread 4
--indice 4
thread 5
--indice 0
--indice 5
thread 20
--indice 1
thread 21
--indice 2
thread 22
thread 6
--indice 3
thread 23
--indice 4
--indice 6
thread 7
thread 24
--indice 7
thread 8
--indice 8
thread 9
--indice 9
--indice 5
thread 10
thread 25
--indice 6
thread 26
--indice 7
thread 27
--indice 10
thread 11
--indice 11
thread 12
--indice 8
--indice 12
thread 13
--indice 13
thread 28
--indice 9
thread 14
--indice 14
thread 29
thread 15
--indice 10
--indice 15
thread 30
thread 16
--indice 16
--indice 11
thread 17
thread 31
--indice 17
thread 18
--indice 18
--indice 12
thread 32
--indice 13
C:Tool (or Pin) caused signal 11 at PC 0xb53aeba5
process killed by signal -10

execution without cilk screen :

amina@amina-laptop:~/projet/cilkplus-install/examples/test$ ./private
thread 0
--indice 0
thread 1
--indice 1
thread 2
--indice 2
thread 3
--indice 3
thread 4
--indice 4
thread 5
--indice 5
thread 6
--indice 6
thread 7
--indice 7
thread 8
--indice 8
thread 9
--indice 9
thread 10
--indice 10
thread 11
--indice 11
thread 12
--indice 12
thread 13
--indice 13
thread 14
--indice 14
thread 15
--indice 15
thread 16
--indice 16
thread 17
--indice 17
thread 18
--indice 18
thread 19
--indice 0
Erreur de segmentation

* second problem : if i comment the lign of code //vars.set_indice(vars.indice() + 1 );

execution with cilk screen :

amina@amina-laptop:~/projet/cilkplus-install/examples/test$ cilkscreen ./private
Cilkscreen Race Detector V2.0.0, Build 1113
thread 0
thread 19
--indice 0
thread 1
--indice 0

Warning: Instrumentation never enabled - no Cilk Plus code found
1 error found by Cilkscreen
process killed by signal -10

execution without cilk screen :

amina@amina-laptop:~/projet/cilkplus-install/examples/test$ ./private
thread 0
--indice 0
thread 1
--indice 0
thread 2
--indice 0
thread 3
--indice 0
thread 4
--indice 0
thread 5
--indice 0
thread 6
--indice 0
thread 7
--indice 0
thread 8
--indice 0
thread 9
--indice 0
thread 10
--indice 0
thread 11
--indice 0
thread 12
--indice 0
thread 13
--indice 0
thread 14
--indice 0
thread 15
--indice 0
thread 16
--indice 0
thread 17
--indice 0
thread 18
--indice 0
thread 19
--indice 0
Erreur de segmentation

Have you an idea for the two problems ?

Thank you a lot for your help,
0 Kudos
SergeyKostrov
Valued Contributor II
451 Views
Thank you for your reply.
I share your opinion that it's a problem of insuffisance of memory. but sometimes it work's fine and sometimes fails with fault segmentation.
...


How much memory do you have on a system?Is it a32-bit or 64-bit?
How big is a Virtual Memory file?

Best regards,
Sergey

0 Kudos
Georg_Z_Intel
Employee
452 Views
Hello,

the problem here is that for a new strand the member ary_ of class strorage is not initialized. A solution for your example would be the following:
[cpp]...

class storage
{
    public:

        storage() {}

        //***** ary

        void set_ary (int *ary) {
            ary_ = ary; // Initialize once for all strands
        }

        void set_ary (int i, int val) {

            ary_ = val;
        }

        int * ary() { return ary_; }


    private:
        static int *ary_;

};

int *storage::ary_ = 0;

...[/cpp]

Since an object of class storage has only a few bytes it's not related to limited memory.

If you used CILK_NWORKERS=1 (only one strand) there's no problem with your original version because only one object of type storage exists which is already initialized correctly. However, more strands (>= 2) require a local copy of storage object, each, (hyper-object) and hence the pointer ary_ is not initialized for strands other than the original one.

Best regards,

Georg Zitzlsberger
0 Kudos
Jim_S_Intel
Employee
451 Views
Hi,

I'm not quite sure what your code is doing with the declaration of the "storage_holder" class, but it looks like you have attempted to define your own reducer object, without declaring a reduce function or identity?
My initial guess is that because your code is changing the views of a hyperobjectdirectly, when a steal occurs and a new view is created, this view is not initialized properly.

In any case, I think the code that may do what you are trying to do can be simpler. If you want to declare an array of width 10000 that persists, then you don't needany reducers.


int main(int argc, char* argv[])
{
int* vars = new int[10000];
cilk_for (int i = 0; i < 10000; i++) {
printf ("thread %d \n", i);
vars = i;
}
printf("End \n");
delete[] vars;
return 0;
}

Alternatively, if you know that each variable "vars" is only used as a local variable inside the loop, you may be able to use a holder. The following post has more information about how you can use builtin holders.

http://software.intel.com/en-us/forums/showthread.php?t=86884

Cheers,

Jim

0 Kudos
amina-jarraya
Beginner
451 Views
Thank you it works fine.
you have reason, the ary variable have to be initialized.
0 Kudos
Reply